首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

看看这个统计更新的SQL如何写呢?

2012-04-27 
看看这个统计更新的SQL怎么写呢?急....在线等...HTML codeMS SQL2000,表tab1中,数据如下:idstukindaccount

看看这个统计更新的SQL怎么写呢?急....在线等...

HTML code
MS SQL2000,表tab1中,数据如下:id   stu    kind   account1    小明   a2    阿东   a3    李四   b4    杨尚   c5    阿强   a6    阿基   b7    要求   a8    文东   a我想实现,按kind统计出每个分类的数量,并更新到account字段,如下:id   stu    kind   account1    小明    a       52    阿东    a       53    李四    b       24    杨尚    c       15    阿强    a       56    阿基    b       27    要求    a       58    文东    a       5请问这个更新的SQL语句怎么写呢?在线等。。。。


[解决办法]
SQL code
update aset a.account =b.countsfrom tab1 a, (select kind,count(1)as counts from tab1 group by kind)bwhere a.kind=b.kind
[解决办法]
SQL code
update tab1 set account=(select count(1) from tab1 where kind=t.kind) from tab1 t 

热点排行