select
COUNT(distinct(case when COL_USERID3 is null then COL_USERID6 end)) as 'aa',
COUNT(distinct(case when COL_USERID3 is null and COL_USERID7 is not null then COL_USERID6 end)) as 'bb',
COUNT(distinct(case when COL_USERID3 is not null then COL_USERID6 end)) as 'cc',
COUNT(distinct(case when COL_USERID3 is not null and COL_USERID7 is not null then COL_USERID6 end)) as 'dd',
SUM(case when COL_USERID3 IS not null then ee end) as 'ee'
from
(
select c.COL_USERID3,c.ee,g.COL_USERID6
from
(
select b.COL_USERID2 as COL_USERID3,COUNT(b.COL_USERID2) as ee
from
(
select COL_USERID as COL_USERID1,min(EventTime) as time1
from ODS_TABLE_A
where EtlDate = '2016-08-12'
and colid LIKE 'heihei%'
group by COL_USERID
)as a
join
(
select COL_USERID as COL_USERID2,eventtime as time2
from ODS_TABLE_A
where EtlDate = '2016-08-12'
and ItemId = '1111111111101'
and colid like 'haha-%'
and colid not like 'haha-skill%'
and colid not like 'haha-fine%'
)as b
on a.COL_USERID1 = b.COL_USERID2 and a.time1 > b.time2
group by b.COL_USERID2
)as c
right join
(
select DISTINCT d.COL_USERID4 as COL_USERID6
from
(
select distinct COL_USERID as COL_USERID4
from MID_TABLE_B
where etldate = '2016-08-12'
)as d
join
(
select COL_USERID AS COL_USERID5
from ODS_TABLE_A
where EtlDate = '2016-08-12'
and colid LIKE 'heihei%'
)as f
on d.COL_USERID4 = f.COL_USERID5
)as g
on c.COL_USERID3 = g.COL_USERID6
)as i
left join
(
select COL_USERID as COL_USERID7
from MID_TABLE_B
where EtlDate = '2016-08-12'
and IsTodayPay = '1'
)as h
on i.COL_USERID6 = h.COL_USERID7 ----------《代码结束》