gpt4 book ai didi

php - Mysql - 如何获取连续预订一定天数的用户?

转载 作者:太空宇宙 更新时间:2023-11-03 11:50:59 25 4
gpt4 key购买 nike

假设我有一个包含以下列的表 (tbl_reservations):

p_id
userid
reservation_id
book_date
db_add_date

p_id userid reservation_id book_date
1 01 124534 2016-02-19 2016-02-19
2 01 124554 2016-02-20 2016-02-20
3 01 124564 2016-02-21 2016-02-21
4 01 167823 2016-02-22 2016-02-22
5 01 12313 2016-02-23 2016-02-23
6 02 134564 2016-02-21 2016-02-21
7 03 197823 2016-02-22 2016-02-22
8 02 13313 2016-02-23 2016-02-23

**Desired Result**

As userid 01 booked reservation since last 5 days regularty it will appear in query result

userid
01

我想获取连续预订了特定天数的用户?

例如我想获得最近 5 天预订的唯一身份用户

任何人都可以帮助我如何为此构建查询吗?这将是一个非常大的帮助。谢谢。

最佳答案

如果您想要在过去五天内预订的唯一用户,那么这样的查询似乎可以满足您的要求:

select userid
from tbl_reservations
where bookdate > date_sub(curdate(), interval 5 day) and bookdate <= curdate()
group by userid;

如果您想要所有日期都预订的用户:

select userid
from tbl_reservations
where bookdate > date_sub(curdate(), interval 5 day) and bookdate <= curdate()
group by userid
having count(*) = 5;

关于php - Mysql - 如何获取连续预订一定天数的用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35577482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com