mysql默认null参与排序时候是最小值
mysql> select * from user order by age asc;
+----+------+------+----------+
| id | name | age | class_id |
+----+------+------+----------+
| 2 | rt | NULL | NULL |
| 1 | smy | 0 | 0 |
+----+------+------+----------+
2 rows in set (0.00 sec)
把null放在后面处理
mysql> select * from user order by if(isnull(age),1,0), age asc;
+----+------+------+----------+
| id | name | age | class_id |
+----+------+------+----------+
| 1 | smy | 0 | 0 |
| 2 | rt | NULL | NULL |
+----+------+------+----------+
2 rows in set (0.00 sec)