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

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

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

select user_id, t1.room_id, room_type, days
from
    (
        select
            user_id,
            room_id,
            DATEDIFF (max(checkout_time), min(checkin_time)) as days
        from
            checkin_tb
        where
            checkin_time >= '2022-06-12 00:00:00'
        group by
            user_id,
            room_id
        having days > 1
    ) t1
    left join guestroom_tb
    on t1.room_id = guestroom_tb.room_id
    order by days, room_id asc, user_id desc;

全部评论

相关推荐

用微笑面对困难:你出于礼貌叫了人一声大姐,大姐很欣慰,她真把你当老弟
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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