当前位置: 代码迷 >> Sql Server >> select in 排序有关问题
  详细解决方案

select in 排序有关问题

热度:28   发布时间:2016-04-27 12:55:34.0
select in 排序问题
select * from table where id in(10,6,9,20)
这样的话 出来的数据是 根据id升序排的

请教下 怎么根据 in() 里的顺序的倒序来排

就是
20
9
6
10
这样排


作用就是 记录文章的浏览历史


后台
asp
access数据库




------解决方案--------------------
SQL code
select * from table where id in(10,6,9,20)order by charindex(',' + cast(id as nvarchar(20)) + ',' ,',10,6,9,20,') desc
------解决方案--------------------
access里用instr函数,
SQL code
select * from table where id in(10,6,9,20)order by Instr("10,6,9,20",","+cstr(id)) desc
  相关解决方案