I have below data coming from join of tables:
UOM SUM PRODUCT MARKING
KG 150 HAIR DRYER HD
KG 150 null HD
KG 7 HEAT GUN HS
KG 3 HEAT GUN HP
Now from the above data, i want to add the SUM Value of null Product to the Product that has the same Marking. For this i have written this query
SELECT MARKUP.MARKING, SUM(PRODUCT.PRODUCT_QUANTITY), MIN(PRODUCT.PRODUCTNAME), MIN(MEASURE.UOM) FROM
PRODUCT INNER JOIN MEASURE on PRODUCT.ID = MEASURE.PRODUCTID
INNER JOIN MARKUP on PRODUCT.MARKUPID=MARKUP.ID
INNER JOIN PRODUCTCODE on PRODUCTCODE.ID = PRODUCT.PRODUCTCODEID
WHERE PRODUCTCODE.ID = '1123'
GROUP BY MARKUP.MARKING
ORDER BY MARKUP.MARKING DESC
SO with this query, i am able to fetch the desired results as shown below
UOM SUM PRODUCT MARKING
KG 300 HAIR DRYER HD
KG 7 HEAT GUN HS
KG 3 HEAT GUN HP
But when the data is like below:
UOM SUM PRODUCT MARKING
KG 102 HAIR DRYER HD
KG 202 HEAT GUN HD
KG 4 HAIR DRYER HS
KG 6 HEAT GUN HS
Then the above query adds the SUM column(i.e. the Product Quantity Column) based on Marking field as shown below
UOM SUM PRODUCT MARKING
KG 304 HAIR DRYER HD
KG 10 HAIR DRYER HS
Which is totally wrong since i don't have any null Product so, adding the product is not required here based on Marking.
Please let me know how can i only add the SUM i.e. the Product Quantity if the Product value is null for the same Marking. If not then it should show all the products with their quantities.
Thanks in advance.