有表结构如下:
table1
id  name shiyong1 shiyong2
1   aaa    yes         no
2   bbb     yse         yse
3   bbb    yes         no
............怎么写sql能查出如下的效果?
name   shiyong1num  shiyong2num
aaa        1                   0
bbb        2                   1

解决方案 »

  1.   

    这个YES,NO和1,2分别代表什么意思?
    你这样可以做个视图就可以了,不用SQL查吧。
    更改名字用AS
      

  2.   

    select sum(case shiyong1 when 'yes' then 1 else 0 end) as shiyong1,sum(case shiyong2 when 'yes' then 1 else 0 end) as shiyong2 from table1 group by name
      

  3.   

    一模一样
    select name,count(shiyong1) as  shiyong1num,count(shiyong2) as shiyong2num from table1
    group by name
      

  4.   

    试试:select name , count(shiyong1num) as shiyong1num,count( shiyong2num) as shiyong2num
    from table 
    group by name
      

  5.   

    我看错了
    同意yingkiller(大飞虫) ( )
      

  6.   

    flyingkiller(大飞虫) , 写的好。
    等会得分多
      

  7.   

    行列转换的问题,以前我在有一篇帖子灌了不少水,参考一下:
    http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=170924
    帖子参见
    http://expert.csdn.net/Expert/topic/1895/1895274.xml?temp=.881344
      

  8.   

    http://expert.csdn.net/Expert/topic/1895/1895274.xml?temp=.7080194
      

  9.   

    同意yingkiller(大飞虫) ( )