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
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
为什么查询结果为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;