1
運行PostgreSQL的7.x版(是的,我升級)CASE語句結果多個字段
例子:
SELECT
CASE
WHEN "substring"(t."Field"::text, 0, 3) = '01'::text THEN 'group one'::text
WHEN "substring"(t."Field"::text, 0, 4) = '123'::text THEN 'group one'::text
WHEN "substring"(t."Field"::text, 0, 5) = '4567'::text THEN 'group two'::text
WHEN "substring"(t."Field"::text, 0, 6) = '99999'::text THEN 'group three'::text
WHEN "substring"(t."Field"::text, 0, 3) = '07'::text THEN 'group three'::text
ELSE NULL::text
END AS new_field,
CASE
WHEN "substring"(t."Field"::text, 0, 3) = '01'::text THEN 'subgroup a'::text
WHEN "substring"(t."Field"::text, 0, 4) = '123'::text THEN 'subgroup a'::text
WHEN "substring"(t."Field"::text, 0, 5) = '4567'::text THEN 'subgroup a'::text
WHEN "substring"(t."Field"::text, 0, 6) = '99999'::text THEN 'subgroup a'::text
WHEN "substring"(t."Field"::text, 0, 3) = '07'::text THEN 'subgroup b'::text
ELSE NULL::text
END AS another_new_field,...
有沒有辦法有一個case語句給兩個字段的結果作爲處理的數據是相同的,它只是不同的標籤。
沒有具體很難肯定地說,但聽起來像是違反3NF的結構,如果兩個列的值的邏輯是相同的。也許不會,因爲你從兩個地方拉,但正如我所說,很難說。 –
耶從一個來源拉,但一個是一個組,一個是一個小組,這個例子並沒有真正顯示這個 –