sql中的排序,如何使用倒序

sql中的排序,如何使用倒序,第1张

sql中的排序使用倒序的步骤如下:

我们需要准备的材料分别是:电脑、sql查询器。

1、首先,打开sql查询器,连接上相应的数据库表,例如test表,以score字段倒序为例。

2、点击“查询”按钮,输入:select * from test order by score desc。

3、点击“运行”按钮,此时会发现score字段按倒序排序查询出了。

select top 300 a.d_id,a.d_name,a.d_adddate,a.d_size,a.D_Count,a.D_Readme,a.D_NameKey,a.big_id,a.nj_id,a.xk_id from

(select 0 AS nid,d_id,d_name,d_adddate,d_size,D_Count,D_Readme,D_NameKey,big_id,nj_id,xk_id FROM d_info where D_NameKey like '%地理%' Union

select 1 AS nid,d_id,d_name,d_adddate,d_size,D_Count,D_Readme,D_NameKey,big_id,nj_id,xk_id FROM d_info where D_NameKey like '%创新%' Union

select 2 AS nid,d_id,d_name,d_adddate,d_size,D_Count,D_Readme,D_NameKey,big_id,nj_id,xk_id FROM d_info where D_NameKey like '%试题%') a,

(select d_id,d_name,d_adddate,d_size,D_Count,D_Readme,D_NameKey,big_id,nj_id,xk_id,count(*) count1

(select d_id,d_name,d_adddate,d_size,D_Count,D_Readme,D_NameKey,big_id,nj_id,xk_id FROM d_info where D_NameKey like '%地理%' Union

select d_id,d_name,d_adddate,d_size,D_Count,D_Readme,D_NameKey,big_id,nj_id,xk_id FROM d_info where D_NameKey like '%创新%' Union

select d_id,d_name,d_adddate,d_size,D_Count,D_Readme,D_NameKey,big_id,nj_id,xk_id FROM d_info where D_NameKey like '%试题%')

group by d_id,d_name,d_adddate,d_size,D_Count,D_Readme,D_NameKey,big_id,nj_id,xk_id) b

where a.d_id=b.d_id and

a.d_name=b.d_name and

a.d_adddate=b.d_adddate and

a.d_size=b.d_size and

a.D_Count=b.D_Count and

a.D_Readme=b.D_Readme and

a.D_NameKey=b.D_NameKey and

a.big_id=b.big_id and

a.nj_id=b.nj_id and

a.xk_id=b.xk_id

order by b.count1 desc

用order by啊比如select * from product order by price,就是根据price这个字段从小到大进行排序如果需要从大到小排,就在后面加一个desc,也就是select * from product order by price desc


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9918272.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存