joshmc joshmc - 3 months ago 8
SQL Question

how do you sum and combine a string sql

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

I'm a beginner so kindly bear with me. Been receiving some great expertise on this website.


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)



Many thanks.

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