应该给每间房子加一个状态,标示是否有人住不就可以了。
如果没有这样的表,可以用一下语句查询:
select distinct 房间号 from your_table where 退床时间 is null。另外,每个床号的居住时间可以用下面语句得出:
select (datediff(d,入住时间,退床时间) + (case when datepart(hh,入住时间)>12 then 0 else 1 end ) + (case when datepart(hh,退床时间)<12 then 0 else 1 end )) from your_table
如果没有这样的表,可以用一下语句查询:
select distinct 房间号 from your_table where 退床时间 is null。另外,每个床号的居住时间可以用下面语句得出:
select (datediff(d,入住时间,退床时间) + (case when datepart(hh,入住时间)>12 then 0 else 1 end ) + (case when datepart(hh,退床时间)<12 then 0 else 1 end )) from your_table
解决方案 »
- 问大虾们一个数据自动输入的问题,望不吝赐教~~~
- 存储过程遇到的问题。Output parameters have not yet been processed. Call getMoreResults().
- 有没有办法不安装SQL SERVER就可以直接用DTSRUN执行包,谢谢!
- windows server 2003 连不上 sql server 2008 r2 报表服务器
- 有没有什么办法将mysql数据库分离,就像sql server一样拷贝分离附加。
- odbc sql server 连接超时,所以执行失败
- 两个表相互查询问题
- 因为数据库正在使用,所以未能获得对数据库的排它访问权。
- 在check约束中如何引用另外一张表中的字段?
- VFP与某些打印机驱动冲突?“致命错误”如何解决?
- 看看这个存储过程怎么不对?
- 从游标中取数,被负值的变量数目不定。如何做
case
(select count(退房时间) from table b where b.退房时间<a.入住时间 and b.房间号=a.房间号)
-(select count(入住时间) from table b where b.入住时间<a.入住时间 and b.房间号=a.房间号)
when 0
then 入住时间 end 入住时间,
case
(select count(退房时间) from table b where b.退房时间<=a.退房时间 and b.房间号=a.房间号)
-(select count(入住时间) from table b where b.入住时间<=a.退房时间 and b.房间号=a.房间号)
when 0
then 入住时间 end 退房时间
into #tmp
from table aselect distinct
房间号,
入住时间,
case
when 入住时间 not is null
then (select min(退房时间) from #tmp b where b.退房时间>a.入住时间)
end 退房时间
from #tmp a
写错了。。
(select count(退房时间) from table b where b.退房时间<a.入住时间 and b.房间号=a.房间号)
-(select count(入住时间) from table b where b.入住时间<a.入住时间 and b.房间号=a.房间号)
when 0
then 入住时间 end 入住时间,是什么意思?