您可以使用
MIN
ever
,当还有
never
with tbl as (
select
v.loc_id
,v.user_id
,TO_CHAR(v.site_visit_date,'YYYY-MM-DD')
,v.site_visit_count
,TO_CHAR(a.action_date,'YYYY-MM-DD')
,a.action_category
,a.action_count
,case when a.action_count >=1 then 'ever' else 'never' end ever_never
from
visits v
left join actions a on v.user_id = a.user_id and v.site_visit_date = a.action_date
order by 1,2,5
)
select
user_id
,MIN(ever_never)
,sum(action_count)
from
tbl
group by
user_id
order by 1,2
检查结果:
http://rextester.com/live/LQDR42614