回 帖 发 新 帖 刷新版面

主题:请问一个select...in排序的问题

select * from 数据表 where 字段名 in ('值1','值3','值2')
每次产生排序都是默认的
有'值1','值2','值3'的纪录
,如何产生的纪录排序是按含有'值1','值3','值2'的纪录这样排序,不知道我有没有说清楚,就是顺着in中的顺序来,而不是默认的排序,请问如何做。

回复列表 (共10个回复)

沙发

select * from 数据表 where 字段名 in ('值1','值3','值2')
order by
case when 字段名 = '值1' then 1
when 字段名 = '值2' then 2
when 字段名 = '值3' then 3
end

板凳

听不明白。。。

3 楼

select * from 数据表 where 字段名 in ('值1','值3','值2')
order by 字段名

4 楼

同上

5 楼

select * from biao where zduan=值1
union
select * from biao where zduan=值3
union
select * from biao where zduan=值2
union
select * from biao where zduan=值?

6 楼

二楼为正解,顶就一个字!!!

7 楼


order by
decode(字段,值1,1,值2,2,值3,3)

8 楼

同意2楼的看法

9 楼

我好像明白你的意思了。但WHERE IN 肯定要排序的。

10 楼

select * from 数据表 where 字段名 in ('值1','值3','值2')
order by
case 字段名 when  '值1' then 1
when '值2' then 2
when '值3' then 3
end

我来回复

您尚未登录,请登录后再回复。点此登录或注册