sql查询语句的排列问题

来源:百度知道 编辑:UC知道 时间:2024/05/30 17:38:19
select top 10 content from Conews where Deleted=false and status=3 order by ID desc

在conews表content里面的内容选择10条按照id号从大到小排列
我的问题:
1、如果我只想查询content里面的第4条记录,这个sql查询应该如何写?
2、如果我想查询content里面的第4、5、6、7、8条记录,这个sql查询又应该如何写?
以下5条的回答都没有正确的,不是提示form的句型错误,就是不能带in等等的,现在我想出了一个马马虎虎的:select Content from content where ID=4 但是显示页面出现了一些<p> <br> 等的东西~~~~
怎么没有人回答了吗?

select top 1 content from (select top 4 * from Conews where Deleted=false and status=3 order by ID desc) order by id

select top 5 content from (select top 8 * from Conews where Deleted=false and status=3 order by ID desc) order by id

你可以利用存储过程:
declare @tablename table(id int,content int)
insert into @tablename select top 10 content,id from Conews where Deleted=false and status=3 order by ID desc
这样就能得到10条记录了,然后
select top 1 content from(
select top 4 content,id from @tablename order by id desc)order by id asc这样就能得到第4第了,第5,6,7,8条类似

1、sql=\"select content from conews where id=4\"
2、sql=\"select content from conews where id in (4,5,6,7,8)\"

select top 1 *
from Conews where ID in (select top 4 ID from Conews where ID in (select top 10 * from Conews where Deleted=false and status=3 order by ID desc) order by ID)
order by ID desc

select top 5 *
from Conews where ID in