日期:2014-05-18  浏览次数:20587 次

这个思路的sql如何写
SQL code

        select  ( select COUNT(*) from tmp  where tmp.f1=v1),
            ( select COUNT(*) from tmp  where tmp.f2=v2),
            ( select COUNT(*) from tmp  where tmp.f3=v3),
            ...            
    
       from    (select  * from table1 where f0 =...) as tmp   



???

------解决方案--------------------
select case when tmp.f1=v1 then .....else 0 end as ...,
case when 实现

------解决方案--------------------
select 
sum(case when f0 = ... and f1 = 'v1' then 1 else 0 end) ,
sum(case when f0 = ... and f2 = 'v2' then 1 else 0 end) ,
sum(case when f0 = ... and f3 = 'v3' then 1 else 0 end) ,
...
from table1