我怎麼能(在子句的SELECT語句排序值排序)排序相同,其中在condtion
查詢順序相同where I.ItemCode in()
序列
記錄
SELECT I.ItemCode,I.ItemName,UM.Name As Unit,
SUM(CASE WHEN Rs.RestaurantID=1 THEN RD.Quantity ELSE Null END) [res1],
SUM(CASE WHEN Rs.RestaurantID=2 THEN RD.Quantity ELSE Null END) [res2],
SUM(RD.Quantity)TOTAL_QTY
FROM DBO.ITEMS I
LEFT JOIN UnitMeasure UM
ON I.UnitMeasureID=UM.UnitMeasureID
LEFT OUTER JOIN DBO.RequisitionDetails RD
ON I.ItemID=RD.ItemID
LEFT JOIN Requisitions R
ON RD.RequisitionID=R.RequisitionID
LEFT JOIN Restaurants Rs
ON R.RestaurantID=Rs.RestaurantID
where I.ItemCode in (355,365,360,275,335,350,395,320,310,340,345,305,325,315,388,300,383,385,250,245,453,326,366,368,375) and r.RequisitionDate='2016-09-23'
GROUP BY I.ItemCode,I.ItemName,UM.Name
嘗試ORDER BY I.ItemCode ASC/DESC。 –