joshmc joshmc - 2 months ago 5
SQL Question

How do you sum and combine a string

How can I get:



pn | min max
------ | ------
ABC123 | 0,0
ABC123 | 1,1
ABC123 | 1,1
ABC123 | 1,1


To:

pn | min max
------ | -------
ABC123 | 3,3



  • Oracle database 11g

  • PL/SQL 11.2.4.0



This is what I have now:

SELECT
PN_INVENTORY_LEVEL.PN,
PN_INVENTORY_LEVEL.MAXIMUM_STOCK || ',' || PN_INVENTORY_LEVEL.MINIMUM_STOCK AS MIN_MAX
FROM
PN_INVENTORY_LEVEL
WHERE ("PN_INVENTORY_LEVEL"."PN" = :PN)

Answer

Try to use

 SELECT
               PN_INVENTORY_LEVEL.PN,
               Sum(PN_INVENTORY_LEVEL.MAXIMUM_STOCK) || ',' || sum(PN_INVENTORY_LEVEL.MINIMUM_STOCK) AS MIN_MAX
    FROM
               PN_INVENTORY_LEVEL
    WHERE ("PN_INVENTORY_LEVEL"."PN" = :PN)
group by PN_INVENTORY_LEVEL.PN
Comments