我想要计算I的数量,但以一种特殊的方式。例如,如果id是在4月份计算的,那么我不想在5月份再次计算该id。所以不包括前几个月统计的id。这是我正在使用的查询。
按1,2从分组中选择门店、月份名(Created_at)、计数(Distinct customer_id);
希望你能帮助我。
提前感谢!
发布于 2021-05-28 18:32:37
只需计算第一次看到客户的次数。一种方法是两个级别的聚合:
select store, date_trunc('month', min_created_at), count(*)
from (select store, customer_id, min(created_at) as min_created_at
from a
group by store, customer_id
) c
group by 1, 2;注意:monthname()不适合用来定义月份,因为它没有考虑年份。如果你真的想忽略年份,你可以使用monthname(),但这似乎并不常见。
发布于 2021-05-28 18:22:30
希望这条sql语句能有所帮助!
从where monthname(created_at)=MONTHNAME(current_date()) group by 1,2中选择商店、月份名称(Created_at)、计数(Distinct customer_id);
https://stackoverflow.com/questions/67736810
复制相似问题