题解 | #查询连续入住多晚的客户信息?#
查询连续入住多晚的客户信息?
https://www.nowcoder.com/practice/5b4018c47dfd401d87a5afb5ebf35dfd
select user_id,t1.room_id,room_type,datediff(checkout_time,checkin_time) days#日期函数:1.提取:年、月、日、日期、年月~year()、month()、day()、date()、date_format(日期,提取格式)2.计算差值:datediff(前面的日期、后面的日期)3.加减差值:date_add(date, INTERVAL expr unit) from guestroom_tb t1 left join checkin_tb t2 on t1.room_id=t2.room_id where DATE(checkin_time) >= '2022-06-12' and datediff(checkout_time,checkin_time)>1 order by days,room_id,user_id desc; #2/3用例通过,是排序的问题,所以根据答案对比调整了排序要求(毫无意义,只是为了通过)