日期:2014-05-17 浏览次数:20789 次
CREATE TABLE #1 (xm varchar(100),gw varchar(100),sl int, sj varchar(100))
INSERT INTO #1 SELECT
'A','AA',100, '2011.1.1' UNION ALL select
'B','BB' , 200, '2011.1.1'UNION ALL select
'C','AA',300,'2011.1.1'UNION ALL select
'A','DD' ,400, '2011.2.1'UNION ALL select
'B','CC',500,'2011.2.1'UNION ALL select
'C','CC' , 600, '2011.2.1'
SELECT a.xm,(SELECT gw FROM #1 WHERE sj='2011.2.1' AND xm=a.xm),sum(a.sl) FROM #1 a
GROUP BY
a.xm