根据程序中的条件进行排序:
...
SELECT
...
order by formattedbookingdate
CASE WHEN isasc IS TRUE THEN
asc
ELSE
desc
END;
...
Postgres抛出错误:
错误:“CASE”或附近的语法错误
第266行:当isasc为真时的情况
最佳答案 我会分开条件,所以你在结束后添加asc或desc,如:
td=# select * from (select generate_series(1,3) a) a order by case when true then a end asc, case when true then a end desc;
a
---
1
2
3
(3 rows)
td=# select * from (select generate_series(1,3) a) a order by case when false then a end asc, case when true then a end desc;
a
---
3
2
1
(3 rows)
是的,我会再想一想为什么我会这样做:)