SQL

1.一列拆为两列

select count(*) from
(select test4.uid uid ,case when test4.money_on>=test4.money_off then ""线上"" else ""线下"" end main_channel
from
(select test3.uid uid,sum(money_on) money_on,sum(money_off) money_off from
(select test.uid uid ,test.money as money_on,0 as money_off from
(select uid,channel,sum(order_sum_money) as money from c3_orders where process_date='2019-03-18' group by uid,channel) test
where test.channel='线上'
union all
select test1.uid uid , 0 as money_on, test1.money as money_off from
(select uid,channel,sum(order_sum_money) as money from c3_orders where process_date='2019-03-18' group by uid,channel) test1
where test1.channel='线下') test3
group by test3.uid) test4 ) test5
where test5.main_channel=""线上"";

posted @ 2019-03-21 11:47  番薯大大  阅读(110)  评论(0编辑  收藏  举报