我已经阅读了几十个关于 CASE 的答案,但不确定这是我需要在这里使用的,它似乎应该可以工作,但它不是:
Data:
OrderNum OrderLine PartNum
200011 1 ABC-1
200011 2 DEF-1
200012 1 XYZ-1
What I would like to return:
OrderNum Item#
200011 MIXED
200012 XYZ-1
What I am returning instead:
OrderNum Item#
200011 ABC-1
200011 MIXED
200012 XYZ-1
我的查询:
SELECT OrderHed.OrderNum,
(CASE WHEN ShipDtl.OrderLine > '1' then 'MIXED' else ShipDtl.PartNum end) as [Item#]
FROM dbo.OrderHed, dbo.ShipDtl
WHERE ShipDtl.Company = OrderHed.Company
AND ShipDtl.OrderNum = OrderHed.OrderNum
GROUP BY OrderHed.OrderNum, ShipDtl.OrderLine, ShipDtl.Part