对列然后按 ORDER BY
Pair Columns then ORDER BY
这一定是一个 PEBCAK 问题,因为它看起来很基础。是否有查询说,“如果 'mon' = 1 THEN ORDER BY 'time' THEN if 'tue' = 1 ORDER BY 'time', THEN if 'wed' = 1按 'time' 排序" ?
+=====+=====+=====+========+
| mon | tue | wed | time |
+=====+=====+=====+========+
| 0 | 1 | 1 | 0100 |
| 0 | 0 | 0 | 2200 |
| 1 | 1 | 1 | 1500 |
| 1 | 1 | 0 | 0600 |
| 0 | 0 | 0 | 1400 |
| 1 | 0 | 1 | 1100 |
+=====+=====+=====+========+
想要的结果:
mon 0600
mon 1100
mon 1500
tue 0100
tue 0600
tue 1500
wed 0100
wed 1100
wed 1500
...
ORDER BY CASE WHEN mon=1 THEN 1 WHEN tue=1 THEN 2 WHEN wed=1 THEN 3 END,
time
这一定是一个 PEBCAK 问题,因为它看起来很基础。是否有查询说,“如果 'mon' = 1 THEN ORDER BY 'time' THEN if 'tue' = 1 ORDER BY 'time', THEN if 'wed' = 1按 'time' 排序" ?
+=====+=====+=====+========+
| mon | tue | wed | time |
+=====+=====+=====+========+
| 0 | 1 | 1 | 0100 |
| 0 | 0 | 0 | 2200 |
| 1 | 1 | 1 | 1500 |
| 1 | 1 | 0 | 0600 |
| 0 | 0 | 0 | 1400 |
| 1 | 0 | 1 | 1100 |
+=====+=====+=====+========+
想要的结果:
mon 0600
mon 1100
mon 1500
tue 0100
tue 0600
tue 1500
wed 0100
wed 1100
wed 1500
...
ORDER BY CASE WHEN mon=1 THEN 1 WHEN tue=1 THEN 2 WHEN wed=1 THEN 3 END,
time