首页 > 数据库技术 > 详细

PostgreSQL的case when

时间:2016-09-26 14:27:15      阅读:277      评论:0      收藏:0      [点我收藏+]
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;

 

PostgreSQL的case when

原文:http://www.cnblogs.com/esther-qing/p/5908955.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!