我有这么几条数据 ID name 1 aa 3 ss 5 gg 2 af 4 te 6 rt 这个已经是排序后的 我第一个要查出top2 那么就是1 3 现在我第2次要查村 5,2 要怎么查 not in的语句如何写? 注ID 是自动增长的
这个问题第1个回答:
注ID 是自动增长的: 你表里记录会这样? 这个问题第2个回答:
按什么排序的啊?
这个问题第3个回答:
select top 2 * from test where id not in (select top 2 id from test)
这个问题第4个回答:
新建一个标识列
select 1,'1' union all select 2,'4' union all select 3,'2' union all select 4,'5' union all select 5,'3' union all select 6,'6'
select top 2 * from @a where id not in (select top 2 id from @a order by name) order by name
可以实现,前提是前后的排序规则要一致 这个问题第12个回答:
ID為自增連續列 select * from tablename where identitycol between n and m
这个问题第13个回答:
如果tablename里没有其他identity列,那么: select identity(int) id0,* into #temp from tablename 取n到m条的语句为: select * from #temp where id0 >=n and id0 <= m 这个问题第14个回答:
我有这么几条数据 ID name 1 aa 3 ss 5 gg 2 af 4 te 6 rt 这个已经是排序后的 >>> 是按哪个字段排序的呢? TOP再结合你排序的那个字段就行了。
这个问题第15个回答:
再不然就这样..
SQL code
SELECT TOP 2 *
from (
select top (4) * from t1 where a not in (select top (2) a from t1)
)a