I have some hotel records on my database. these records contain start date and end dates of how long a person stays at the hotel.
我的数据库上有一些酒店记录。这些记录包含一个人在酒店停留多长时间的开始日期和结束日期。
what sql command can I write to compare the two dates to see how many people only stayed in the hotel for 1 night?
我可以写什么sql命令来比较两个日期,看看有多少人只在酒店住了一晚?
thanks
谢谢
sample data:
样本数据:
start date end date
30-JAN-16 02-FEB-16
12-FEB-16 18-FEB-16
13-FEB-16 14-FEB-16
1 个解决方案
#1
1
You can filter the differences the two dates which is number of days and find count on it:
您可以过滤两个日期的差异,即天数并找到它的计数:
select count(*)
from your_table
where end_date - start_date <= 1
#1
1
You can filter the differences the two dates which is number of days and find count on it:
您可以过滤两个日期的差异,即天数并找到它的计数:
select count(*)
from your_table
where end_date - start_date <= 1