Reputation: 73
I am trying to shift rows with value less than current date at the bottom of the result set. I've this query
SELECT
r_id AS Id,
f_title AS Title,
f_desc AS Description,
f_upload_file AS File,
ABS(DAYOFYEAR(f_valid_date)- DAYOFYEAR(CURDATE())) AS Deadline,
f_added_on as 'Added On'
FROM t_documents
WHERE
f_rec_status= TRUE
ORDER BY Deadline ASC
and it gives this result:
Any help will be appreciated.
Upvotes: 1
Views: 109
Reputation: 263803
Try this,
ORDER BY (CASE WHEN Deadline IS NULL
THEN 1 ELSE 0 END) ASC, Deadline ASC
Upvotes: 2