表
id gx cj
1 100 a
2 150 b
3 180 c
4 200 d写段代码
查询gx=100时
结果如下:
gx cj cj1
100 a b
当搜索gx =100时 显示gx=100的cj 以及 gx>100 的cj。不过不能把所有大于100的都显现出来只显示下道工序的cj
id gx cj
1 100 a
2 150 b
3 180 c
4 200 d写段代码
查询gx=100时
结果如下:
gx cj cj1
100 a b
当搜索gx =100时 显示gx=100的cj 以及 gx>100 的cj。不过不能把所有大于100的都显现出来只显示下道工序的cj
from [table] t where gx=100
insert into tb values(1 ,100, 'a')
insert into tb values(2 ,150, 'b')
insert into tb values(3 ,180, 'c')
insert into tb values(4 ,200 ,'d')
goselect gx , cj , cj1 = (select top 1 cj from tb where id > t.id order by id) from tb t where gx = 100
drop table tb/*gx cj cj1
----------- ---------- ----------
100 a b(所影响的行数为 1 行)*/
select gx,cj,(select top 1 cj from [table] where gx>t.gx order by gx) as cj1
from [table] t where gx=100
create table tb(id int,gx int,cj varchar(10))
insert into tb values(1 ,100, 'a')
insert into tb values(2 ,150, 'b')
insert into tb values(3 ,180, 'c')
insert into tb values(4 ,200 ,'d')
goselect gx,cj,(select top 1 cj from [table] where gx>t.gx order by gx) as cj1
from [table] t where gx=100 /*gx cj cj1
----------- ---------- ----------
100 a b(所影响的行数为 1 行)*/
if object_id('tempdb.dbo.#') is not null drop table #
create table #(id int, gx int, cj varchar(8))
insert into #
select 1, 100, 'a' union all
select 2, 150, 'b' union all
select 3, 180, 'c' union all
select 4, 200, 'd'select * from
(select top 1 gx, cj from # where gx=100)a,
(select top 1 cj cj1 from # where gx>100 order by gx) b/*
gx cj cj1
----------- -------- --------
100 a b
*/