我正在尝试为下表创建自定义视图:
(PLACE和PLACE_PRIMARY指的是另一个表中的外键)
视图基本上组合了ORG中具有相同名称的任何行,并将它们的PLACE组合成一个列表,但我很困惑如何执行WHERE子句。以下是我到目前为止的情况:
SELECT org.name,
STRAGG(refdata.display_name) place,
STRAGG(refdata.display_name) place_primary
FROM table_organization org,
table_reference_data refdata
WHERE org.name = org.name
GROUP BY org.name
ORDER BY org.name;
更新:
我得到以下内容来提取PLACE列的列表:
SELECT org.name, stragg(DISTINCT org.place)
FROM table_organization org, table_reference_data refdata
GROUP BY org.name;
问题是它目前只显示外键而不是table_reference_data中的字符串值。
答案 0 :(得分:0)
听起来你需要改变这个:
SELECT org.name, stragg(DISTINCT org.place)
FROM table_organization org, table_reference_data refdata
GROUP BY org.name;
到
SELECT org.name, stragg(DISTINCT refdata.stringvalue)
FROM table_organization org
JOIN table_reference_data refdata ON refdata.keycol = org.place
GROUP BY org.name;
(更改refdata.keycol和refdata.stringvalue以使用真实的列名称。)