SQL 排序 选择后面2条数据

来源:百度知道 编辑:UC知道 时间:2024/04/29 11:33:53
数据库结构:
ID CONTENT
1 A1
2 A2
3 A3
4 A4
5 A5

我想要的输出结果是
1:A4
2:A5

意思就是,order by id asc
但又选择后面2条输出……前面的全部不要
请问如何写?
maize09 说的输出结果是
2:A5
1:A4

这个表是无限扩展的……
意思就是,顺序取出数据,然后输出最后的N条数据

补修改:
<%
set rs=server.CreateObject("adodb.recordset")
strsql="select * from table where CONTENT in (select top 2 CONTENT from table order by id desc) order by id"
rs.open strsql,conn,1,1
if not rs.eof then
c_count=rs.recordcount
for i=1 to c_count
%>
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><%=i%>:</td>
<td><%=rs("CONTENT")%></td>
</tr>
</table>
<%
rs.movenext
next
end if
rs.close
set rs=nothing
%>

不好意思没有看清题目

create table test
(
id int ,
content varchar(30)
)

insert into test
select 1,'A1' union all
select 2,'A2' union all
select 3,'A3' union all
select 4,'A4' union all
select 5,'A5&