SQL汇总统计语句


select qdyyd,sum(case when qdyyd='CK' and amt<=600 AND dc='二档' then 1
when qdyyd='XS' and amt<=600 AND dc='二档' then 1
when qdyyd='WC' and amt<=600 AND dc='二档' then 1
when qdyyd='LJ' and amt<=600 AND dc='二档' then 1
when qdyyd='SX' and amt<=600 AND dc='二档' then 1
when qdyyd='LZ' and amt<=600 AND dc='二档' then 1
when qdyyd='XW' and amt<=600 AND dc='二档' then 1
else 0 end ) as '100元面值(单位:户)',
sum(case when qdyyd='CK' and ((amt<600 AND dc='一档') or (amt>600 AND dc='二档')) then 1
when qdyyd='XS' and ((amt<600 AND dc='一档') or (amt>600 AND dc='二档')) then 1
when qdyyd='WC' and ((amt<600 AND dc='一档') or (amt>600 AND dc='二档')) then 1
when qdyyd='LJ' and ((amt<600 AND dc='一档') or (amt>600 AND dc='二档')) then 1
when qdyyd='SX' and ((amt<600 AND dc='一档') or (amt>600 AND dc='二档')) then 1
when qdyyd='LZ' and ((amt<600 AND dc='一档') or (amt>600 AND dc='二档')) then 1
when qdyyd='XW' and ((amt<600 AND dc='一档') or (amt>600 AND dc='二档')) then 1
else 0 end ) as '150元面值(单位:户)',sum(case when qdyyd='CK' and amt>=600 AND dc='一档' then 1
when qdyyd='XS' and amt>=600 AND dc='一档' then 1
when qdyyd='WC' and amt>=600 AND dc='一档' then 1
when qdyyd='LJ' and amt>=600 AND dc='一档' then 1
when qdyyd='SX' and amt>=600 AND dc='一档' then 1
when qdyyd='LZ' and amt>=600 AND dc='一档' then 1
when qdyyd='XW' and amt>=600 AND dc='一档' then 1
else 0 end ) as '200元面值(单位:户)' into tjnew
from tj group by qdyyd order by qdyyd asc

你可能感兴趣的:(sql)