有一个表table(id,name),里面有数据{(1,aa_1),(2,xx_1),(3,zz_1),(4,xx_2)},现在要按字段name来排序,但又要把所有的xx的先排在前面,用升序。前高手们指点一二。
解决方案 »
- mysql如何在一个数据库所有表都增加一个字段?多谢!
- 关于PostgreSQL性能优化的问题
- java 代码执行一个insert语句Error: There is no 'bb'@'%' registered
- user表中max_updates,max_questions,max_connections,max_user_connections几个字段的含义
- mysql存储过程的中文问题
- 租用国外的空间,用JSP写入MYSQL中的中文是“?”,救命啊!
- 紧急:Unix/Linux平台下PHP+MySQL做后台数据库问题请教!
- Myql select * 与select count(*) 求大神。。在线等。
- 怎么在MySQL里保存“变量名-变量值对”?
- 请教统计问题
- 如何快速找出丢失数据?
- 请问,怎么样更改数据库的字符集?
union
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 name from table where left(name,2)='xx'
union
select name from table where left(name,2)<>'xx' order by name
那又跟select name from table order by name 没什么两样。有更好的办法吗?
from 表名
order by case when left(name,2)='xx' then 1 else 2 end, name