select s.*,
(case when row_number() over (partition by user_id order by s_date) = 1
then 'Yes' else 'No'
end) as new_customer
from sales s;
然后可以为摘要聚合:
select s_date, sum(case when new_customer = 'Yes' then 1 else 0 end)
from (select s.*,
(case when row_number() over (partition by user_id order by s_date) = 1
then 'Yes' else 'No'
end) as new_customer
from sales s
) s
group by s_date
1条答案
按热度按时间m2xkgtsf1#
可以使用窗口函数:
然后可以为摘要聚合: