mysql中null值的排序問題分析 如下表t_user: name age zhangsan 1 lisi NULL wangwu 2 www.2cto.com 執行一下sql: Sql代碼 select * from t_user order by age; name age lisi NULL zhangsan 1 wangwu 2 實際上我們是想將沒有填寫age的記錄放在最後,我們可以 Sql代碼 select * from t_user order by age is null, age; name age zhangsan 1 wangwu 2 lisi NULL 為什麼會這樣?可以這樣來理解: Sql代碼 select * from t_user order by age is null, age; 等價於: Sql代碼 select * from (select name, age, (age is null) as isnull from t_user) as foo order by isnull, age;