急救,添加新字段的问题。
在StockOrderInfo表中查询语句是(
SELECT GameServerCode, SUM(CASE WHEN issent = 1 THEN 1 ELSE 0 END) AS I1,SUM(CASE WHEN issent = 0 THEN 1 ELSE 0 END) AS I2 FROM StockOrderInfo
GROUP BY GameServerCode
),查询结果有1000多条记录。
我要追加到视图V1(其中2000多条记录)每列的后面,条件是GameServerCode=GameServerCode,视图中GameServerCode有重复的。
------解决方案--------------------select a.*,bI1,b.I2 into #temp
from v1
left join
(
SELECT GameServerCode, SUM(CASE WHEN issent = 1 THEN 1 ELSE 0 END) AS I1,SUM(CASE WHEN issent = 0 THEN 1 ELSE 0 END) AS I2 FROM StockOrderInfo
GROUP BY GameServerCode) b
on a.GameServerCode=b.GameServerCode