关于SQL日期

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

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

select
    ct.user_id,
    gt.room_id,
    gt.room_type,
    datediff(ct.checkout_time,ct.checkin_time) days
# datediff(A,B)表示「从 B 到 A」跨越的整天数
from
    checkin_tb ct
    inner join guestroom_tb gt on ct.room_id = gt.room_id # left join也行
where
    ct.checkin_time >= "2022-06-12"
	# sql日期格式'2022-06-12 00:00:00'
    and datediff(ct.checkout_time,ct.checkin_time) >= 2
order by
    4 asc,
    2 asc,
    1 desc

全部评论

相关推荐

03-08 18:11
门头沟学院 Java
Java抽象小篮子:海投就完事了,简历没什么问题,最大问题是学历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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