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

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

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

select user_id, a.room_id, room_type, datediff(checkout_time, checkin_time) days
from guestroom_tb a
inner join (
    select info_id, room_id, user_id, substring_index(checkin_time,' ',1) checkin_time, substring_index(checkout_time,' ',1) checkout_time
    from checkin_tb
) b
on a.room_id = b.room_id
where checkin_time = '2022-06-12' and checkout_time > '2022-06-13'
order by days, room_id, user_id desc;

关键在于使用datediff函数求出最大连续入住天数,datediff(X,Y)函数X为大日期,Y为小日期,否则相减得负数。

同时需要注意本题目的业务问题,需要连续入住多晚(入住一晚将不统计在内)。

全部评论

相关推荐

03-17 19:21
门头沟学院 Java
面试官_我太想进步了:正常企查查显示的员工一般比设计的少
点赞 评论 收藏
分享
野猪不是猪🐗:我assume that你must技术aspect是solid的,temperament也挺good的,however面试不太serious,generally会feel style上不够sharp
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务