informix 14.10 如何连接三个表进行双重映射
Posted
技术标签:
【中文标题】informix 14.10 如何连接三个表进行双重映射【英文标题】:informix 14.10 How to join three table for double mapping 【发布时间】:2020-10-06 05:44:41 【问题描述】:我有 3 个表 c1,map1,map2 像这样:
-- t1 map1 map2
-- c1 cm cn m1 m2 n1 n2
1 1 1 1 a 1 x
2 1 1 2 b 2 y
3 2 1
4 1 2
5 2 2
而输出应该是这样一个表格:
1 a x
2 a x
3 b x
4 a y
5 b y
如果只是表map1,问题很简单
select c1,m1 from t1 cross join map1 where t1.c1=map1.m1
有人可以帮忙吗?
【问题讨论】:
【参考方案1】:从表面上看,这应该可以完成工作:
SELECT t1.c1, m1.m2, m2.n2
FROM t1
JOIN map1 AS m1 ON t1.cm = m1.m1
JOIN map2 AS m2 ON t1.cn = m2.n1
用此 SQL 测试以确认结果:
CREATE TEMP TABLE t1(c1 INTEGER NOT NULL PRIMARY KEY, cm INTEGER NOT NULL, cn INTEGER NOT NULL);
CREATE TEMP TABLE map1(m1 INTEGER NOT NULL PRIMARY KEY, m2 CHAR(1) NOT NULL);
CREATE TEMP TABLE map2(n1 INTEGER NOT NULL PRIMARY KEY, n2 CHAR(1) NOT NULL);
INSERT INTO t1 VALUES(1, 1, 1);
INSERT INTO t1 VALUES(2, 1, 1);
INSERT INTO t1 VALUES(3, 2, 1);
INSERT INTO t1 VALUES(4, 1, 2);
INSERT INTO t1 VALUES(5, 2, 2);
INSERT INTO map1 VALUES(1, 'a');
INSERT INTO map1 VALUES(2, 'b');
INSERT INTO map2 VALUES(1, 'x');
INSERT INTO map2 VALUES(2, 'y');
SELECT t1.c1, m1.m2, m2.n2
FROM t1
JOIN map1 AS m1 ON t1.cm = m1.m1
JOIN map2 AS m2 ON t1.cn = m2.n1;
输出:
c1 m2 n2
1 a x
2 a x
3 b x
4 a y
5 b y
【讨论】:
b_r_i_l_l_i_a_n_t @alwaysstudent 。 . .如果这回答了您的问题,您应该接受答案。 @Gordon Linoff :我完全忘记了它以上是关于informix 14.10 如何连接三个表进行双重映射的主要内容,如果未能解决你的问题,请参考以下文章