我在mysql表中有三列
我想按以下顺序显示记录
首先显示那些
的记录pubdate >=currdate() and status=1 and order by pubdate ASC
然后表中没有任何条件的所有剩余记录。
请帮助mysql查询
答案 0 :(得分:0)
我试试:
SELECT * FROM (SELECT * FROM mytable WHERE pubdate>=CURDATE() AND status=1 ORDER BY pubdate ASC) AS a
UNION all
SELECT * FROM (SELECT * FROM mytable WHERE pubdate<CURDATE() OR status!=1) AS b;
答案 1 :(得分:0)
在满足条件时给予一些权重,并在ORDER BY中使用它:
SELECT *,
IF(pubdate >= CURRENT_DATE AND status = 1, 10, 0) weight
FROM
thetable
ORDER BY weight DESC, pubdate ASC