我有一个多租户架构,这是我的查询从1个表中检索列名和从另一个表中检索值。
SELECT
MAX(CASE WHEN TME.EXTENSION_ID = '555' THEN EXT.value END) A,
MAX(CASE WHEN TME.EXTENSION_ID = '556' THEN EXT.value END) B,
MAX(CASE WHEN TME.EXTENSION_ID = '559' THEN EXT.value END) C,
MAX(CASE WHEN TME.EXTENSION_ID = '560' THEN EXT.value END) D,
MAX(CASE WHEN TME.EXTENSION_ID = '557' THEN EXT.value END) E,
MAX(CASE WHEN TME.EXTENSION_ID = '558' THEN EXT.value END) F,
MAX(CASE WHEN TME.EXTENSION_ID = '561' THEN EXT.value END) G,
MAX(CASE WHEN TME.EXTENSION_ID = '562' THEN EXT.value END) H
FROM TENANTDATAEXTENSION EXT, TENANTMETADATAEXTENSION TME
WHERE TME.EXTENSION_ID = EXT.EXTENSION_ID;
这只返回每个Extension_ID的1行。但是,我有超过1行。我怎么得到所有?
当前输出:
Column Name: A B C D E F G H
Column Values: A1 B1 C1 D1 E1 F1 G1 H1
预期产出:
Column Name: A B C D E F G H
Column Values: A1 B1 C1 D1 E1 F1 G1 H1
A2 B2 C2 D2 E2 F2 G2 H2
A3 B3 C3 D3 E3 F3 G3 H3
TENANTDATAEXTENSION表如下所示:
Column Name: Extension_ID Extension_Label
Column Values:
555 A
556 B
557 E
558 F
559 C
560 D
561 G
562 H
TENANTMETADATAEXTENSION表如下所示:
Column Name: Extension_ID Value.
Column Values:
555 A1
555 A2
555 A3
556 B1
556 B2
556 B3
557 E1
557 E2
557 E3
etc.........