PHP MySQL按第一列排序,如果第二个为NULL [英] PHP MySQL order by first column, if second NULL
本文介绍了PHP MySQL按第一列排序,如果第二个为NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有桌子:
id | post_date | bumped_post_date
1 | date | NULL
2 | date | date2
好的,我知道如何按post_date
进行排序,但是只有当bumped_post_date
为 NULL 时,我才不会按post_date
进行排序.
Ok, I know how to order by post_date
, but I wan't to order by post_date
only when bumped_post_date
is NULL.
当bumped_post_date
不为NULL时,则按它排序,而不是按post_date排序(但如果为NULL,则按post_date排序).谢谢,抱歉我的英语不好.
When bumped_post_date
is not NULL, then order by it, not by post_date ( But if NULL, then order by post_date ). Thanks and sorry for my bad English.
推荐答案
您可以在
select * from my_table
order by case when bumped_post_date is null
then post_date else bumped_post_date end
这篇关于PHP MySQL按第一列排序,如果第二个为NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文