将null排在最后
order by if(isnull(price), 99999, price) asc
将0排在最后
1.Order BY表达式 SELECT nian ,price from Tbl ORDER BY price!=0 desc,price asc 2.算术法 SELECT nian ,price,1/price as od from Tbl ORDER BY od desc
项目实战(价格是string类型)
order by price!=0.00 desc ,if(isnull(price+0), 99999, price+0) asc
1、一般的order by 语句其返回的结果为
- SELECT `vcenter_ip`, `status`, `sla_id` FROM vm_list ORDER BY sla_id ASC;
2、这个很显然不是我想要的结果,修改SQL如下[红色为关键语句]
- SELECT `vcenter_ip`, `status`, `sla_id` FROM vm_list ORDER BY sla_id is NULL, sla_id = 0, sla_id ASC;