stock idWarehouse Warehousname idorder
-492 1 xyz 1
-24 3 abc 1
-492 1 xyz 2
-24 3 abc 2
我希望得到以下表格的结果
xyz abc idorder
-492 -24 1
-492 -24 2
答案 0 :(得分:1)
如果Warehousname
的值集有限,您可以这样做:
SELECT MAX(CASE WHEN Warehousname='xyz' THEN stock END) AS xyz,
MAX(CASE WHEN Warehousname='abc' THEN stock END) AS abc,
idorder
FROM TableName
GROUP BY idorder
示例结果:
xyz abc idorder
-492 -24 1
-492 -24 2
SQL Fiddle中的示例结果。