SQL基础

CASS WHEN.....THEN 基础使用~!

select e.chairdevice_id,SUM(IFNULL(e.d,0))/SUM(IFNULL(e.c,0)) from (select b.chairdevice_id,CASE when contents_type=1 then b.a END c,CASE when contents_type=2 then b.a END d from (select  chairdevice_id,contents_type,count(contents_type) a from n_tcpdatas_2_061102 where contents like '%50%' and contents_type='2' group by chairdevice_id
union
select  chairdevice_id,contents_type,count(contents_type) a from n_tcpdatas_2_061102 where contents like '%50%' and contents_type='1' group by chairdevice_id) b) e GROUP BY e.chairdevice_id

 

posted on 2018-06-11 14:40  Darian_zhy  阅读(103)  评论(1)    收藏  举报

导航