Question10: How can I list non-contignous data?
  In database pubs, I create a table test using statement as below, and I insert several row as below
create table test
( id int primary key )
goinsert into test values (1 )
insert into test values (2 )
insert into test values (3 )
insert into test values (4 )
insert into test values (5 )
insert into test values (6 )
insert into test values (8 )
insert into test values (9 )
insert into test values (11)
insert into test values (12)
insert into test values (13)
insert into test values (14)
insert into test values (18)
insert into test values (19)
goNow I want to list the result of the non-contignous row as below,how can I do it?
Missing after Missing before
------------- --------------
6 8
9 11
...本题我可以推敲到
select id as [Missing after] from test t where not exists(select 1 from test where id=t.id+1)
select id as [Missing after] from test t where not exists(select 1 from test where id=t.id-1)
但不知道该怎么将此两查询粘合起来形成一个查询中的两列,而且去不掉第一个1和最后一个19此外提供的参考答案
  select id from test t where not exists(select 1 from test where id=t.id+1)or not exists(select 1 from test where id=t.id-1)
是在一列中就显示了答案不符合题意