PostgreSQL的case when


select tt.dict_label as display_item,t1.ratio from
(select t.product_level,round(sum(case when t.detect_result='2' then 1 else 0 end)::NUMERIC/count(1)::NUMERIC,4) as ratio
from t_detect_record t
where t.district='3' and t.e_commerce_platform='3'
group by t.product_level) t1
left join t_dict tt on t1.product_level=tt.dict_value
where tt.dict_type='product_level'


select country, sum( case when sex = '1' then   population else 0 end),  --男性人口

 

 sum( case when sex = '2' then  population else 0 end)   --女性人口

 

from table_a   group by country;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM