我有3张 table
表 1 landing_modules
- l_id
- 我的名字
- l_模块
- l_变体
- l_version
表 2 类别
- c_id
- 姓名
表 3 category_landing_modules
- l_id
- c_id
l_id
和 c_id
是从 table_3
到 table_1
和 table_2
的外键分别。现在需要的输出是
landing_modules
中的所有行,这将是
SELECT * FROM landing_modules;
但另外我想要结果集中的一列作为 category_ids
,它应该包含来自 table_3 - category_landing_modules
的相应 c_ids(category_ids)
。
结果集看起来像
- l_id
- 我的名字
- l_模块
- l_变体
- l_版本
- c_ids
最佳答案
您可以使用相关子查询。
SELECT lm.*,
ARRAY(SELECT clm.c_id
FROM category_landing_modules clm
WHERE clm.l_id = lm.l_id) c_ids
FROM landing_modules lm;
关于sql - 如何创建虚拟列并在连接后填充数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57217089/