我有以下查询,它返回基于逗号分隔列表的行
Select * from Table where RecordID in (22,15,105,1,65,32)
我希望此查询的结果按照列表中 ID 的顺序返回。这可以用 SQL 实现吗?
提前致谢
最佳答案
select * from Table
where RecordID in (22,15,105,1,65,32)
order by (
case RecordID
when 22 then 1
when 15 then 2
when 105 then 3
when 1 then 4
when 65 then 5
when 32 then 6 end)
关于SQL-按列表顺序排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6609184/