如果我查询返回如下内容,我有一个“表 A”:
DPSF0010001 | 4973
DPSF0010002 | 139
DPSF0010003 | 266
DPSF0010004 | 437
DPSF0010005 | 391
DPSF0010006 | 146
DPSF0010007 | 100
DPSF0010008 | 78
DPSF0010009 | 141
DPSF0010010 | 253
DPSF0010011 | 425
DPSF0010012 | 491
DPSF0010013 | 501
DPSF0010014 | 477
DPSF0010015 | 382
...
.
.
该查询有多个列 DPSFxxxx。DPSFxxxxx 可以引用另一个表,其中“DPSF0010001”可以解码为字符串:“Total:”。例如:
Total: | dpsf0010001
Under 5 years | dpsf0010002
5 to 9 years | dpsf0010003
10 to 14 years | dpsf0010004
15 to 19 years | dpsf0010005
20 to 24 years | dpsf0010006
25 to 29 years | dpsf0010007
30 to 34 years | dpsf0010008
35 to 39 years | dpsf0010009
40 to 44 years | dpsf0010010
45 to 49 years | dpsf0010011
50 to 54 years | dpsf0010012
55 to 59 years | dpsf0010013
60 to 64 years | dpsf0010014
65 to 69 years | dpsf0010015
...
.
.
我想DPSF0010001
在我的查询中用表 B 中的关联字符串替换它。例如:
前:
SELECT "DPSF0010001" from TableA;
DPSF0010001
-------------
4973
(1 row)
后:
SELECT "DPSF0010001" from TableA;
Total:
-------------
4973
(1 row)
如何使用查找值替换查询中的列名?我知道我可以使用 AS 重命名,如何扩展它以在不同的表中查找值?