sql语句 90天内消费2次的会员

表有会员号 消费时间
2025-04-24 04:28:47
推荐回答(2个)
回答1:

select 会员号 from 表
where datediff(dd,消费时间, getdate() )<=90 and datediff(dd,消费时间, getdate() )>=0
group by 会员号 having count(1)=2

回答2:

select 会员号 from 表
where 消费时间 between dateadd(day,-90,getdate()) and getdate()
group by 会员号 having count(*)>=2