This will apparently put null values for myDate at the bottom of the result set. What's the logic behind how this is being executed?
SELECT * FROM myTable
WHERE ...
ORDER BY CASE WHEN myDate IS NULL THEN 1 ELSE 0 END, myDate;
This is your order by
:
ORDER BY (CASE WHEN myDate IS NULL THEN 1 ELSE 0 END),
myDate
The first expression for the order by says "Give the NULL
values a value of 1 (for the sort) and non-NULL
values a value of 0". Well, you are sorting in ascending order, so the NULL
values go last.
If you want them first, use desc
:
ORDER BY (CASE WHEN myDate IS NULL THEN 1 ELSE 0 END) DESC,
myDate
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다