select sum(c)
form (
select count(*) as c from 一个表aa where ID1='yes'
union all
select count(*) as c from 一个表aa where ID2='yes'
union all
select count(*) as c from 一个表aa where ID3='yes'
union all
select count(*) as c from 一个表aa where ID4='yes'
union all
select count(*) as c from 一个表aa where ID5='yes'
) t

解决方案 »

  1.   

    我在版主提供的语句上稍微做了点改动,查询结果如图:
    为什么查询结果为0呢?改动代码:select sum(c) as bb from ( 
    select count(*) as c from aa where ID1='%yes%' 
    union all 
    select count(*) as c from aa where ID2='%yes%' 
    union all 
    select count(*) as c from aa where ID3='%yes%' 
    union all 
    select count(*) as c from aa where ID4='%yes%' 
    ) t;