I have a table
OrderID Qty ShopID
-----------------------
1 50 10
1 50 11
2 10 15
2 10 18
The person ordered the same order at different shops (they will later decide which one will supply it), but I must only show one qty per order, please help setting the qty = 0 where the orderid is the same and shopid > min(shopID)
e.g.
OrderID Qty ShopID
-----------------------
1 50 10
1 0 11
2 10 15
2 0 18
This is just an example of the real world problem pls
You can try something like this:
Basically, I “partition” the data by
OrderID– so each row within a given order gets assigned a consecutiveRowNum.In the select from the CTE (Common Table Expression), I return the quantity as stored in the table for the order with
RowNum = 1, and I suppress that quantity and return 0 instead for all additional rows for that sameOrderID.This gives me an output of: