简体   繁体   中英

How can I get the expected result in Sybase as below list sql, remove not changed row

create table #test2(
id int identity, 
request int null,
step_no int null)

insert into #test2(request) values (12)
insert into #test2(request) values (12)
insert into #test2(request) values (30)
insert into #test2(request) values (30)
insert into #test2(request) values (30)
insert into #test2(request) values (12)
insert into #test2(request) values (24)
insert into #test2(request) values (30)
insert into #test2(request) values (30)
insert into #test2(request) values (24)


Get result:
12
30
12
24
30
24

Try below sql: (I change the table name, so u need to recheck the sql)

select 
    a.id,
    a.request 
    --, aa.id, aa.request
from @test2 a
left join
 (
    select c.id,c.request from @test2 c 
 ) aa on a.request = aa.request and a.id = aa.id + 1
 where aa.id is null and aa.request is null

Result Table:

id          request
----------- -----------
1           12
3           30
6           12
7           24
8           30
10          24

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM