I couldnt find a forum for sql so Im going to post here. If Im in the wrong forum then please move me.
I have a table with following data
OID, Product, Condition, QTY
1, Product A, NEW, 60
2, Product A, B, 60
3, Product A, C, 40
4, Product B, NEW, 30
5, Product B, C, 20
I want to write my procedure so that when I execute it, it will return a table as such.
Product Name, NEW, B, C
Product A, 60, 60, 40
Product B, 30, 0, 20
SELECT PRODUCT,(CASE WHEN CONDITION LIKE 'NEW' THEN QTY END) AS NEW, (CASE WHEN CONDITION LIKE 'B' THEN QTY END) AS B, (CASE WHEN CONDITION LIKE 'C' THEN QTY END) AS C FROM TEST
I got to the point where it will show different quantities in corresponding column but I was unable to merge them into single row.
Thank you in advance