表:
id(int)
type(varchar) name(varchar) time(DateTime)
1
优
a
2004-12-23
2
优
b
2004-12-30
3
中
c
2005-01-12
4
良
d
2005-01-10
5
中
e
2005-01-09
现在要按:
1.优,良,中
2.时间 排序
也就是结果为:
2
优
b
2004-12-30
1
优
a
2004-12-23
4
良
d
2005-01-10
3
中
c
2005-01-12
5
中
e
2005-01-09
如果只有‘优良中’应该效率还可以,但如果太多项而且表比较大的话效率就低了。
select *
from table1
where type='优'
UNION all
select *
from table1
where type='良'
UNION ALL
select *
from table1
where type='中'
order by 4