i'm trying to get posts ordering by rep
, but if post.date
older than one day then it must be ordered in normal order (means id
field order).
here is posts
table (date is unix timestamp);
id | date | rep | title ------------------------------ 10 | today | 0 | lorem 9 | today | 1 | ipsum 8 | yesterday | 2 | dolor 7 | 2 days ago | 2 | sit 6 | 3 days ago | 10 | amet
expected result (is it impossible or nonsense trying to get a result like that, or am i confused);
id | title ---------- 9 | ipsum 10 | lorem 8 | dolor 7 | sit 6 | amet
here is what i tested that returns too old posts first;
ORDER BY CASE WHEN p.date + unix_timestamp(from_unixtime(p.date) + interval 1 day) > unix_timestamp(now()) THEN p.rep ELSE p.id END DESC // or ... END DESC, p.id DESC