假设我有一个表(tbl_reservations),其中包含以下列:
[]
我想让连续预订了几天的用户?
e.g。我想获得过去5天预订的唯一身份用户
有人可以帮我解决这个问题吗?这将是一个非常大的帮助。谢谢。
答案 0 :(得分:3)
如果您想要在过去五天内预订的唯一身份用户,那么此类查询似乎可以满足您的需求:
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;
答案 1 :(得分:0)
尝试此查询:
SELECT userid
from tbl_reservations
WHERE book_date >= DATE_SUB(CURDATE(), INTERVAL 5 DAY) AND book_date <= CURDATE()
GROUP BY userid
HAVING COUNT(*) = 5;
答案 2 :(得分:0)
试试这个sql.You得到从当前日期预订列表的最后%天数
select count(userid), userid
from tbl_reservations
where (book_date > DATE_ADD(CURDATE(), INTERVAL -5 DAY) and book_date<=CURDATE())
group by userid
having count(*) = 5;