场景:
mysql中如果使用正序 asc 排序,那么默认是把排序字段值为空的条目数据,优先排到前面,这明显不符合需求,解决如下
一、重现问题
-- 按排序号-正序
select shop_id,
sort_num,
update_time
from t_shop_trend_content
where shop_id = 'Q00402'
order by sort_num asc, update_time desc;
-- 按排序号-倒序
select shop_id,
sort_num,
update_time
from t_shop_trend_content
where shop_id = 'Q00402'
order by sort_num desc, update_time desc;
正序输出:
倒叙输出:
小结:
1、由结果输出可以看到 desc 倒序没问题,排序字段值为空的排在后面
2、但是使用 asc 正序排序有问题,会把排序字段值为空的排在前面,不符合要求
二、使用 if() 函数解决
-- 按排序号-正序
select shop_id,
sort_num,
update_time
from t_shop_trend_content
where shop_id = 'Q00402'
order by if(sort_num is not null, sort_num, 10000000000) asc, update_time desc;
输出:
小结:
1、从结果看符合预期
2、排序字段非空才参与排序,为空直接给个大的默认值排到最后







![[Eigen中文文档] 在 BLAS/LAPACK 、英特尔® MKL 和 CUDA 中使用 Eigen](https://img-blog.csdnimg.cn/358fbb477d3443c9abc1a775be3f46a6.png#pic_center)











![【FATE联邦学习】get out put data报错output dir = result[“directory“]KeyError:directory“](https://img-blog.csdnimg.cn/d6aef5b554db436fb81e147c17d2bbd6.png)