题解 | 查询连续入住多晚的客户信息?

查询连续入住多晚的客户信息?

https://www.nowcoder.com/practice/5b4018c47dfd401d87a5afb5ebf35dfd

select *
from (
select ct.user_id,
ct.room_id,
gt.room_type,
datediff(ct.checkout_time,ct.checkin_time) as days
from checkin_tb ct 
left join guestroom_tb gt on gt.room_id=ct.room_id
where date(ct.checkin_time)='2022-06-12'
) tmp_step1
where days>1
order by days asc,room_id asc,user_id desc

代码倒是不难,主要是需求里没有明确说要住的日期大于1天。

另外记得按需排序(照连续入住天数的升序排序,再按照房间号的升序排序,再按照客户id的降序排序

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务