运行 PostgreSQL 7.x(是的,我正在升级)
例子:
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语句给出两个字段作为结果,因为处理的数据是相同的,只是标签不同。