34,588
社区成员
发帖
与我相关
我的任务
分享
1:
;
with cte1 as
(
select * from b,(select count(列1) rowcnt1,count(列2) rowcnt2 from 表2) B
)
update cte1 set a=rowcnt1,b=rowcnt2
2:t-sql到目前为止还不支持行值构造器,虽然Ansi支持
--try
update b
set a = (select rows from sysindexes where id=object_id('表2') and indid=0 ),b = (select sum(列2) from 表2 )
from 表1 b
update b
set a = count(列1) ,
b = sum(列2)
from 表1 b
,表2
update
a
set
a = B.rowcnt,
b = B.rowsum
from
tb1 a,(select count(col1) rowcnt,sum(col2) rowsum from tb) B;
update b
set a = t.a,b = t.b
from 表1 b ,
(select count(列1) a,sum(列2) b from 表2) t
DECLARE @I INT
select @I=count(列1) from 表2
DECLARE @B INT
select @B=SUM(列2) from 表2
update b
set a =@I,b = @B
from 表1 b
DECLARE @I INT
select @INT=count(列1) from 表2
DECLARE @B INT
select @B=SUM(列2) from 表2
update b
set a =@I,b = @B
from 表1 b
UPDATE A SET
a = B.rowcnt,
b = B.rowsum
FROM tb1 AS A,
(SELECT COUNT(col1) AS rowcnt,SUM(col2) AS rowsum FROM tb) AS B;
--用變量
DECLARE @I INT
select @INT=count(列1) from 表2
update b
set a =@I,b = @I
from 表1 b
update b set b.a=a.a,b.b=a.b
from 表1 b,(select count(列1) a,max(列2) b from 表2) a
update b
set a = t.a,b = t.b
from 表1 b ,
(select count(列1) a,sum(列2) b from 表2) t
where b.aaa=1
如果你的aaa在表1,这样.update b
set a = t.a,b = t.b
from 表1 b ,
(select count(列1) a,sum(列2) b from 表2 where aaa = 1) t