SQL查询结果自定义排序
一般情况之下,我们可以使用ORDER BY ...ASC或DESC来做查询排序。如:
SELECT * FROM [dbo].[SalesPerformance] ORDER BY [Salesman] ASC GO
Source Code
如果需要求某一些值先排在前面,其余的数据再按规则排序,如Salesman的值‘S0008’,‘S0032’,‘S0022’排在前3位:
SELECT * FROM [dbo].[SalesPerformance] ORDER BY CASE WHEN [Salesman] = ‘S0008‘ THEN ‘1‘ WHEN [Salesman] = ‘S0032‘ THEN ‘2‘ WHEN [Salesman] = ‘S0022‘ THEN ‘3‘ ELSE [Salesman] END ASC
Source Code
相关推荐
dreamhua 2020-05-10
dreamhua 2020-05-08
liuyang000 2020-04-25
elitechen 2020-02-15
xuanlvhaoshao 2020-01-23
xiaopang 2020-01-05
liuyang000 2019-12-24
dreamhua 2019-12-17
一对儿程序猿 2019-10-30
dreamhua 2019-10-28
Phplayers 2016-04-02
Unfinishcode 2019-07-12
li00lee 2012-11-06
BrotherWind 2019-07-01
wangxingg 2015-10-22
zjyzz 2014-12-08
Wlitttle 2015-03-30
zjyzz 2011-01-29