当前位置: 代码迷 >> Sql Server >> 看看这个统计更新的SQL如何写呢?
  详细解决方案

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

热度:101   发布时间:2016-04-27 13:09:11.0
看看这个统计更新的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
  相关解决方案