比方说,我有两个表:加入的设置返回函数(json_array_elements)结果与表列
User_Combination
+--------+----------------+
| id | combination |
+--------+----------------+
| 6 | [1, 2] |
| 9 | [2, 3] |
+--------+----------------+
颜色
+--------+----------------+
| id | color |
+--------+----------------+
| 1 | Blue |
| 2 | Yellow |
| 3 | Green |
+--------+----------------+
我想加盟结果json_array_elements(color)
与元素的id
。例如,
select json_array_elements(color) as CombinationID
from User_Combination where id = 6;
结果是
+-------------------+
| CombinationID |
+-------------------+
| 1 |
| 2 |
+-------------------+
我无法加入CombinationID
与Colors.id
。当我尝试SQL命令,例如:
select json_array_elements(article_data) AS articlesInOutfits (color) as CombinationID
from User_Combination uc JOIN Colors co ON co.id = articlesInOutfits;
或
select json_array_elements(article_data) AS articlesInOutfits (color) as CombinationID
from User_Combination uc JOIN Colors co ON co.id = uc.articlesInOutfits;
它说articlesInOutfits
不存在。
有什么建议吗?
你的Postgres的版本? –
使用9.3.3。令人惊讶的是,unnest不起作用。 – NateW
你能解决一些令你困惑的错误吗? 'json_array_elements(color)'? “元素”指的是什么?显示数据类型和约束的实际表格定义会更有用。 –