SQL查询语句如下:
select * from table where (ID = 10) or (ID = 32) or (ID = 22) or (ID = 76) or (ID = 13) or (ID = 44)我想让结果按10,32,22,76,13,44的顺序检索出来,但是检索后的顺序变成了按ID排序的:10,13,22,32,44,76。请问如何让结果不排序呢???多谢!
select * from table where (ID = 10) or (ID = 32) or (ID = 22) or (ID = 76) or (ID = 13) or (ID = 44)我想让结果按10,32,22,76,13,44的顺序检索出来,但是检索后的顺序变成了按ID排序的:10,13,22,32,44,76。请问如何让结果不排序呢???多谢!
case id
when 10 then 1
when 32 then 2
when 22 then 3
when 76 then 4
when 13 then 5
when 44 then 6
END as seq
from table
where (ID = 10)
or (ID = 32)
or (ID = 22)
or (ID = 76)
or (ID = 13)
or (ID = 44)
order by seq
select * from table where ID in(10,32,22,76,13,44);
不行的,一样是顺序排的,我试过了.你可以这样
(select * from table where ID = 10) union (select * from table where ID = 32) union (select * from table where ID = 22) union (select * from table where ID = 76) union (select * from table where ID = 13) union (select * from table where ID = 44)
INSTR(',10,32,22,76,13,44,', ','+id+',') as seq
from table
where id in(10,32,22,76,13,44)
order by seq
不错,这样也可以
select *
from table
where id in(10,32,22,76,13,44)
order by instr(',10,32,22,76,13,44,', ','+id+',')
你可以order by random()
OEDER BY 列名[ASG] -- 升序
好象可以这样用,没试过!!!
select *
from table
where id in(10,32,22,76,13,44)
order by field (id,10,32,22,76,13,44);
(
select table.id, 600 as from table where table.id=10 union
select table.id, 500 as from table where table.id=32 union
select table.id, 400 as from table where table.id=22 union
select table.id, 300 as from table where table.id=76 union
select table.id, 200 as from table where table.id=13 union
select table.id, 100 as from table where table.id=44
) as a order by desc;
from table
where id in(10,32,22,76,13,44)
order by field (id,10,32,22,76,13,44);
我试过了,可是里面说field无法识别的函数,怎么办啊?