say your table name is "yourtable", try something likeselect identity(int, 1,1) id, je, rq into #temp1 from yourtable y where not exists (select 1 from yourtable where bh = y.bh-1 and je = y.je)select identity(int, 1,1) id, je, rq into #temp2 from yourtable y where not exists (select 1 from yourtable where bh = y.bh+1 and je = y.je)select t1.rq as kssj, t2.rq as jssj, t1.je
from #temp1 t1
inner join #temp2 t2
on t1.id = t2.id
from #temp1 t1
inner join #temp2 t2
on t1.id = t2.id
解决方案 »
- 这种错误提示怎么办?
- SQL server 2000个人版启动问题?
- 一道关于模糊查询的题
- 【请教】SQL语句有无可能在两个不同的Access库中做连接查询???
- 今天做了一道面试题 有高手帮忙解决下吗?
- 求一个练表查询的分页存储过程,带统计
- 急:存储过程问题,各位高人帮忙看看错在哪了,不能得出正确结果,谢谢:) 分不够,再加!
- 请问:扩展存储过程如何传回OUTPUT的参数?
- 数据库编程中是用绑定好,还是不用绑定,优缺点有是什么?请各位大虾指点
- 数据库中某一字段存取多个字符串,如何匹配其中一个呢?
- 怎么实现多表连接查询
- 我的SQLSERVLER出现了很奇怪的问题啊,超急求救!!!!!!!(在线等)
insert #你的表 values(1 , '2003-01-01', 10)
insert #你的表 values(2, '2003-01-02' , 10)
insert #你的表 values(3 ,'2003-01-03' , 15)
insert #你的表 values(4 , '2003-01-04' , 15)
insert #你的表 values(5 , '2003-01-05' , 10)
insert #你的表 values(6, '2003-01-06' , 10)
insert #你的表 values(7 , '2003-01-07' , 20)
insert #你的表 values(8 , '2003-01-08' , 10)
insert #你的表 values(9, '2003-01-09' , 10)declare @a int,@b int
set @a=0
select *,0 flag into #b from #你的表update #b set @a=case when je=@b then @a else @a+1 end,@b=je,flag=@aselect min(rq) kssj,max(rq) jssj,max(je) je from #b group by flag
go
drop table #你的表,#b
------------------------------------------------------ ------------------------------------------------------ -----------
2003-01-01 00:00:00.000 2003-01-02 00:00:00.000 10
2003-01-03 00:00:00.000 2003-01-04 00:00:00.000 15
2003-01-05 00:00:00.000 2003-01-06 00:00:00.000 10
2003-01-07 00:00:00.000 2003-01-07 00:00:00.000 20
2003-01-08 00:00:00.000 2003-01-09 00:00:00.000 10(所影响的行数为 5 行)
(select rq from tmp where bh/2=cast(bh as float(6,2))/2 ) b
on a.rq+1=b.rq where bh/2<>cast(bh as float(6,2))/2