病人的体温每小时量一次病人 时间 温度
甲 0:00 37.3
甲 1:00 37.2
甲 2:00 37.1.. ... ...
甲 23:00 37.9.. ... ...
乙 1:00 37.2
.. ... ...丁 ... ...
.. ... ...
求 每个病人 温度连续超过37.4 的最长时段比如 甲的时段 是 14:00-20:00丁的时段 是 1:00-2:00 等等 温度是随机变化的,没有规律。如果只有一个小时(不连续)超过37.4 ,就不显示。2000系统
甲 0:00 37.3
甲 1:00 37.2
甲 2:00 37.1.. ... ...
甲 23:00 37.9.. ... ...
乙 1:00 37.2
.. ... ...丁 ... ...
.. ... ...
求 每个病人 温度连续超过37.4 的最长时段比如 甲的时段 是 14:00-20:00丁的时段 是 1:00-2:00 等等 温度是随机变化的,没有规律。如果只有一个小时(不连续)超过37.4 ,就不显示。2000系统
解决方案 »
- 请问如何动态增加生成临时表的字段?
- 急急求..哪位大哥知道哪有SQL2000开发版下载啊? 最好英文的, 没有的话中文也行
- 关联查询:表1中有学号和每次考试成绩,表2有学号和姓名,查询生成新的表,包括学号、成绩、姓名
- SQLServer的数据上传问题.
- update触发器能不能不再触发?(找高手)
- 哪里有SQL Server 2000 4IN1的.ISO文件下载啊?
- 数据库的设计问题
- 请教::查询条件顺序与执行效率有无关系。。
- SQL查询结果中如何将一行数据转换成一列数据
- 新学求助:C#连接数据库的窗体调试出现问题:未处理SQLCEEXCEPTION,无法加载与 8080 版本的 ADO.NET 提供程序相对应的 SQL Serv
- sql2000打sp4补丁不报错,就是打不上,为什么?
- 100%结贴率 游标实现BOM多级查询
from tab a,tab b
where a.病人 = b.病人
and a.温度>=37.4
and b.温度>=37.4
and a.时间 < b.时间
and not exists (
select 1
from tab
where 病人 = a.病人
and 温度<37.4
and 时间 > a.时间
and 时间 < b.时间
)
from tab a,tab b
where a.病人 = b.病人
and a.温度>=37.4
and b.温度>=37.4
and a.时间 < b.时间
and not exists (
select 1
from tab
where 病人 = a.病人
and 温度<37.4
and 时间 > a.时间
and 时间 < b.时间
)
and isnull((
select top 1 温度
from tab
where 病人 = a.病人
and 时间 < a.时间
order by 时间 desc
),0)<37.4
and isnull((
select top 1 温度
from tab
where 病人 = b.病人
and 时间 > b.时间
order by 时间
),0)<37.4
create table #tb
(病人 nvarchar(10),时间 nvarchar(10) ,温度 float)
insert #tb
select '甲', '22:00', 37.0 union all
select '甲', '21:00', 37.8 union all
select '甲', '20:00', 37.6 union all
select '甲', '19:00', 37.9 union all
select '甲', '0:00', 37.7 union all
select '甲', '1:00', 37.8 union all
select '甲', '2:00', 37.6 union all
select '甲', '23:00', 36.9 union all
select 'A', '0:00', 37.3 union all
select 'A', '1:00', 37.2 union all
select 'A', '2:00', 37.4 union all
select 'A', '23:00', 37.5 union all
select 'B', '23:00', 36.9 union all
select 'B', '0:00', 36.3 union all
select 'B', '1:00', 37.4 union all
select 'B', '2:00', 37.6 union all
insert #tb
select '乙', '1:00', 37.6 union all
select '乙', '0:00', 37.5 union all
select '乙', '23:00', 37.7 union all
select '乙', '2:00', 37.7 union all
select '乙', '22:00', 37.7select identity(int,1,1) as num,* into #T from #tb where 温度>=37.4 order by 病人,cast(replace(时间,':00','') as int)
select cast(replace(时间,':00','') as int)-num as ggid,* into #T1 from #T order by num
select 病人,min(时间) as minTime,max(时间) as maxTime into #T2 from #T1 group by 病人,ggid select t1.病人,
t1.minTime+'-'+isnull(t2.maxTime,t1.maxTime) as 时间段
from #T2 as t1
left join #T2 as t2
on t1.病人=t2.病人
and t1.maxTime='23:00'
and t2.minTime='0:00'
where not (t1.minTime='0:00' and exists(select 1 from #T2 as t where t.病人=t1.病人 and t.maxTime='23:00'))
and (t1.minTime<>t1.maxTime)
drop table #T
drop table #T1
drop table #T2