数据库排序问题 select * from product where id in(5,4,6,100,798,1,43,65,12)

来源:百度知道 编辑:UC知道 时间:2024/06/01 02:02:22
怎样按 id in(5,4,6,100,798,1,43,65,12)
里面的数字排序?
现在搜索出来的信息是按id 顺序排的
用的是MYSQL,
效率要高的

select * from product where id =5
union
select * from product where id =4
union
select * from product where id =6
union
select * from product where id =100

……

这个可用,就是效率差点~

可以增加一个字段,比如N,对应5,4,6,100,798,1,43,65,12分别添加值为1-9个数字,然后再用这个字段排序即可。order by n~

呵呵,你可以加个伪列
select
列,decode(id,5,1,4,2,6,3,100,4,798,5,1,6,43,7,65,8,12,9,0) p_no from product where id in(5,4,6,100,798,1,43,65,12)
order by p_no

decode(id,5,1,4,2,6,3,100,4,798,5,1,6,43,7,65,8,12,9,0) p_no 是排序伪列

select * from product
where id in(5,4,6,100,798,1,43,65,12)
order by id;

select * from product where id =5
union
select * from product where id =4
union
select * from product where id =6
union
select * from product where id =100

……