Created
April 20, 2016 02:35
-
-
Save levantoan/3516e67d8afd55e6ed68c0e3f24f59b3 to your computer and use it in GitHub Desktop.
sắp xếp theo ID, những ID nào chẵn thì xếp tăng dần, ID lẻ thì giảm dần
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
sắp xếp theo ID, những ID nào chẵn thì xếp tăng dần, ID lẻ thì giảm dần | |
VD: | |
5 | |
3 | |
1 | |
2 | |
4 | |
6 | |
Kết quả: | |
2 | |
4 | |
6 | |
5 | |
3 | |
1 | |
*/ | |
SELECT ID, ID%2 as sort | |
FROM `wp_posts` | |
ORDER BY sort, | |
(CASE WHEN `sort` = 0 THEN `ID` end) ASC, | |
(CASE WHEN `sort` = 1 THEN `ID` end) DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment