create table A3 (车次 varchar(10),站序 int,站名 varchar(10))
insert into A3
select 'N115', 1 , '丹东'
union all
select 'N115', 5 , '沈阳'
union all
select 'N116', 5 , '丹东'
union all
select 'N116', 1 , '沈阳'
union all
select 'N117', 2 , '丹东'
union all
select 'N117', 7 , '沈阳'
----
--Try It
select 车次,sum(case 站名 when '丹东' then -站序 else 站序 end ) as 站序
from a3
group by 车次
having sum(case 站名 when '丹东' then -站序 else 站序 end )>0