查询排序问题
有一个表table(id,name),里面有数据{(1,aa_1),(2,xx_1),(3,zz_1),(4,xx_2)},现在要按字段name来排序,但又要把所有的xx的先排在前面,用升序。前高手们指点一二。
------解决方案--------------------select name from table where left(name,2)= 'xx ' order by name
union
select name from table where left(name,2) <> 'xx ' order by name
哈哈
------解决方案--------------------select *
from 表名
order by case when left(name,2)= 'xx ' then 1 else 2 end, name