在不知道ID的情况下 用一条语句查询出 倒叙排列 Tid为20110304的第11条至22条的记录 SQL
答案:3 悬赏:10 手机版
解决时间 2021-04-24 01:26
- 提问者网友:戎马万世
- 2021-04-23 06:47
用SQL 语句 在不知道ID的情况下 用一条语句查询出 倒叙排列 Tid为20110304的第11条至22条的记录 SQL
最佳答案
- 五星知识达人网友:长青诗
- 2021-04-23 07:47
SQLSERVER:先选出倒叙的前22条记录,前10条记录;然后查询前22条记录中ID不在前10条这个集合的结果:
select * from (select top 22 * from table where tid = '20110304' order by id desc) a
where not exists (select 1 from (select top 10 * from table where tid = '20110304' order by id desc) b where b.id = a.id)
ORACLE与上相同
select * from (select * from table where tid = '20110304' and rownum <= 22 order by id desc) a
where not exists (select 1 from (select * from table where tid = '20110304' and rownum <= 10 order by id desc) b where b.id = a.id)
select * from (select top 22 * from table where tid = '20110304' order by id desc) a
where not exists (select 1 from (select top 10 * from table where tid = '20110304' order by id desc) b where b.id = a.id)
ORACLE与上相同
select * from (select * from table where tid = '20110304' and rownum <= 22 order by id desc) a
where not exists (select 1 from (select * from table where tid = '20110304' and rownum <= 10 order by id desc) b where b.id = a.id)
全部回答
- 1楼网友:长青诗
- 2021-04-23 10:37
SQL SERVER 数据库:(本身数据是正序还是倒叙排列的,若是正序排列的)
SELECt *
FROM (SELECt TOP 11 *
FROM (SELECt TOP 22 * FROM Table_Name WHERe TId = '20110304' ORDER BY ID DESC) AS A
ORDER BY ID ASC) AS B
ORDER BY ID DESC
MYSQL数据库:
SELECt * FROM Table_name WHERe Tid = '20110304' ORDER BY ID DESC Limit 10,12
- 2楼网友:山君与见山
- 2021-04-23 09:18
select top 5 bookid from 'table_name' by bookid desc
你看看这样行不行?
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯