您的位置:首页 > 服装鞋帽 > 女装 > Update Select

Update Select

luyued 发布于 2011-01-19 06:16   浏览 N 次  
表tb1及数据如下:
ID A B
---------- ---------- ----------
1 10 20
2 1 2
3 3 2
表tb2及数据如下:
ID A B
---------- ---------- ----------
1 10 20
2 10 20
根据表tb2的id更新表tb1对应的a,b的值。
update tb1 set (a,b) = (select a,b from tb2 where id = tb1.id) where id in (select distinct id from tb2)
ID A B
---------- ---------- ----------
1 10 20
2 10 20
3 3 2
---------------------------------------------------------------------------------------------------------
表tb2及数据如下:
ID A B
---------- ---------- ----------
1 10 20
2 10 20
3 3 2
1 20 40
2 20 40
根据ID分组求A,B的和,然后更新表tb1
update tb1 set (a,b) = (select sum(a),sum(b) from tb2 where id = tb1.id) where id in (select distinct id from tb2)
ID A B
---------- ---------- ----------
1 30 60
2 30 60
上一篇:《领袖风采TB2》 下一篇:加油!
图文资讯
广告赞助商