题解 | 查询连续入住多晚的客户信息?
select c.user_id,c.room_id,g.room_type,datediff(checkout_time,checkin_time) days from checkin_tb c left join guestroom_tb g on c.room_id=g.room_id where c.checkin_time>='2022-06-12' and datediff(checkout_time,checkin_time) >=2 order by days asc,room_id asc,user_id desc;
1、datediff()
大的时间在前面
2、从6.12起:
where c.checkin_time>='2022-06-12',不用date_format也能识别