日期:2014-05-17 浏览次数:20522 次
CREATE TABLE #tb (c1 INT, c2 VARCHAR(10),c3 VARCHAR(10) ) INSERT INTO #TB select 1, 'a', 'b' union all select 2, 'c', 'd' union all select 3, 'e', 'f' SELECT a.* ,b.sc FROM #tb a,(SELECT SUM(c1) sc FROM #tb)b /* c1 c2 c3 sc ----------- ---------- ---------- ----------- 1 a b 6 2 c d 6 3 e f 6 (3 行受影响) */
------解决方案--------------------
select a.*,b.c4 from tb a, (select sum(c1) as c4 from tb) b