SQL Dates问题-统计在过去6个月中至少2个月内至少下过一次订单的用户



我的时间表是2020年第一学期——>1/1到30/6我想计算在6个月内至少2个月内(或以上)至少下过1次订单的用户

我的数据看起来像:User_id, order_date(例如01/01/2020)

正在研究红移btw

您可以通过以下方式使用组:

select user_id
from your_Table t
where <date between condition>
group by user_id 
having count(distinct date_trunc(month, order_date)) > 1

最新更新