我正在尝试按不按字母顺序排列的名称列表对项目进行排序。完成列表后,我尝试按字母顺序继续其余部分,而不是我最初选择的列表。
参见示例:
INPUT:
print 'Results:'
select * from Geniuses
order by ('Charles Babbage',
'Albert Einstein',
'Adrien-Marie Legendre',
'Niels Henrik Abel')
然后最后按字母顺序对其余的进行排序...
OUTPUT:
Results:
Charles Babbage ... details
Albert Einstein ...
Adrien-Marie Legendre ...
Niels Henrik Abel ...
Arthur Cayley ...
...
select * from Geniuses
order by
-- First, order by your set order...
case FullName
when 'Charles Babbage' then 1
when 'Albert Einstein' then 2
when 'Adrien-Marie Legendre' then 3
when 'Niels Henrik Abel' then 4
else 5
end,
-- Then do a secondary sort on FullName for everyone else.
FullName
EDIT:
我看到您的评论,每个用户都可以配置它。在这种情况下,你必须有一个FavoriteGeniuses
跟踪哪个用户喜欢哪个的表Geniuses
,然后在该表中指定排序顺序:
select *
from
Geniuses g left join
FavoriteGeniuses fg
ON fg.GeniusID = g.GeniusID
AND fg.UserID = @UserID
order by
-- The higher the number, the first up on the list.
-- This will put the NULLs (unspecified) below the favorites.
fg.SortPriority DESC,
f.FullName
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)