我有一个电影数据库。我想按发布日期排序,但是当released
日期丢失(空或空)时,我希望按dateAdded
排序
SELECT
movie.ID,
Title,
released,
dateAdded
FROM
movie
WHERE
dateAdded is not null
and (released <= CURDATE() or released is null or released ='')
ORDER BY released DESC
LIMIT 50
答案 0 :(得分:4)
通常你这样做:
{{1}}
这有点滥用,因为它无法正确编制索引,但可以处理相对大量的数据,而不会太糟糕。
答案 1 :(得分:2)
您最好使用标准SQL的ISNULL
:
COALESCE
ORDER BY COALESCE(released, dateAdded) DESC