select: 从表a中选择前n个记录,按降序排列,怎么select?

yueyue 2001-10-15 11:18:22
...全文
340 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
smartdonkey 2001-10-15
  • 打赏
  • 举报
回复
错了
改正:
select col1,col2 from(select top n col1,col2 from mytable) newtable order by col1 desc
如何


smartdonkey 2001-10-15
  • 打赏
  • 举报
回复
select col1,col2 from(select top n col1,col2 from mytable) order by col1
如何
KingSunSha 2001-10-15
  • 打赏
  • 举报
回复
什么数据库? 版本号?
不同的数据库处理方法不一样的.
blueflame 2001-10-15
  • 打赏
  • 举报
回复
比如:
select top 10 * from filebook where bid<>9999 and reid=0 order by fhits desc
yueyue 2001-10-15
  • 打赏
  • 举报
回复
楼上的两位试过了吗?
select a.au_id from ( select top 8 au_id from authors ) as a order by au_id desc
也不对。
我说的是选出前N条,这N条按降序排列
balloy 2001-10-15
  • 打赏
  • 举报
回复
select top n * from a order by b desc
a_fee 2001-10-15
  • 打赏
  • 举报
回复
支持sql-3的数据库,都可用select top N column_name from a order by b dsec
yueyue 2001-10-15
  • 打赏
  • 举报
回复
按字段b降序排列
yueyue 2001-10-15
  • 打赏
  • 举报
回复
呵,对了。
不知有没有更简单的语句
oyo111111 2001-10-15
  • 打赏
  • 举报
回复
好吧,这个总该可以了吧
select a.au_id from (select b.au_id from authors b order by b.au_id) a order by a.au_id desc
oyo111111 2001-10-15
  • 打赏
  • 举报
回复
排序和不排序结果是不一样的,不可相提并论。
yueyue 2001-10-15
  • 打赏
  • 举报
回复
可是
select au_id from authors order by au_id desc
结果是按au_id的顺序排序的呀
oyo111111 2001-10-15
  • 打赏
  • 举报
回复
要明确一点下面二句的au_id结果是不一样的
select * from authors
select au_id from ahthors
所以
select top 8 * from authors
select top 8 au_id from ahthors
得出au_id结果也是不一样的
你要哪个
yueyue 2001-10-15
  • 打赏
  • 举报
回复
楼上的对是对了。
但是*不是太浪费了吗?我只要au_id
oyo111111 2001-10-15
  • 打赏
  • 举报
回复
select * from (select top 8 * from authors) tmp_table order by au_id desc
试试, 没问题可以加分了。
yueyue 2001-10-15
  • 打赏
  • 举报
回复
这是全部:
172-32-1176
213-46-8915
238-95-7766
267-41-2394
274-80-9391
341-22-1782
409-56-7008
427-17-2319
472-27-2349
486-29-1786
527-72-3246
648-92-1872
672-71-3249
712-45-1867
722-51-5454
724-08-9931
724-80-9391
756-30-7391
807-91-6654
846-92-7186
893-72-1158
899-46-2035
998-72-3567

这是选择后的:
722-51-5454
712-45-1867
648-92-1872
527-72-3246
427-17-2319
409-56-7008
238-95-7766
213-46-8915

语句:
select au_id from (select top 8 au_id from authors) newtable order by au_id desc

KingSunSha 2001-10-15
  • 打赏
  • 举报
回复
同意smartdonkey(聪明的毛驴)!
yueyue 2001-10-15
  • 打赏
  • 举报
回复
我用的是sql server2000中自带的数据库pubs.
从表authors中查询au_id前8个,按降序排列
yueyue 2001-10-15
  • 打赏
  • 举报
回复
ms sql server 2000

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧