0
例如起見,有五列在一個表中month
:Postgres的選擇串聯列名
- month.week1
- month.week2
- month.week3
- month.week4
- month.week5
的數量通過函數
EXTRACT(WEEK FROM NOW()) - EXTRACT(WEEK FROM DATE_TRUNC('month', NOW())) + 1
如何選擇列colX
確定的?這是我迄今爲止
SELECT month.week || (
EXTRACT(WEEK FROM NOW())
- EXTRACT(WEEK FROM DATE_TRUNC('month', NOW())) + 1
)::text
FROM month
但是,這給我的錯誤
ERROR: column month.week doesn't exist SQL state: 42703
或者僅僅是'CASE(周表達式)當1那麼...當2 ...'爲了避免重複(真的很長)周表達式。 – pozs