查询:
WITH first_names AS (SELECT DISTINCT fname FROM voters)
SELECT name
from nicknames
WHERE groupi = (
SELECT nn.groupi
FROM nicknames AS nn
WHERE name = 'john'
) AND name != 'john' AND upper(name) = ANY(first_names);
错误:
column "first_names" does not exist
如何从select创建数组并在where语句中使用它?
答案 0 :(得分:0)
WITH first_names AS (SELECT DISTINCT fname FROM voters)
SELECT name
from nicknames
JOIN first_names on fname = upper(name)
WHERE groupi = (SELECT nn.groupi FROM nicknames AS nn WHERE name = 'john') AND name != 'john'
;
答案 1 :(得分:0)
你在这里混淆辅助语句名称和列。 first_names
是您SELECT DISTINCT
提供的结果的名称,fname
是其中包含的列的名称。
不评论整体查询的正确性,更正的语句将使用正确的列名。
WITH first_names AS (SELECT DISTINCT fname
FROM voters)
SELECT name
FROM nicknames
WHERE groupi = (
SELECT nn.groupi
FROM nicknames AS nn
WHERE name = 'john'
) AND name != 'john' AND upper(name) = ANY (first_names.fname);