使用CTE和临时列的PostgreSQL SQL查询

r9f1avp5  于 2023-11-18  发布在  PostgreSQL
关注(0)|答案(1)|浏览(142)

我正在尝试使以下查询工作:

WITH cte AS (
  SELECT org_uid, uid, category, severity, source, created_at, 
  updated_at, delivery_date, finding_id, client_id, client_note, 
  definition, recommendations, details, resources, tags, text, type, sub_category, 
  (SELECT CAST(EXTRACT(EPOCH FROM MAX(fs.remediated_at) - findings.created_at) AS INTEGER) FROM "public"."findings-subjects" fs WHERE fs.finding_uid = findings.uid) AS time_to_remediate 
  FROM "public"."findings" 
  WHERE org_uid = '127cb14a-bbbb-dddd-aaaa-451e7cea3f94'
) SELECT org_uid, uid, category, severity, source, created_at, updated_at, delivery_date, 
finding_id, client_id, client_note, definition, recommendations, details, 
resources, tags, text, type, sub_category, time_to_remediate 
WHERE time_to_remediate BETWEEN 3 AND 7 
LIMIT 1000 
OFFSET 0

字符串
不幸的是,我得到一个错误,说ERROR: column "org_uid" does not exist at character 491我不知道在查询中的错误在哪里。任何帮助将不胜感激。

6tr1vspr

6tr1vspr1#

您的主查询不包含FROM子句。
在倒数第三行前加上FROM cte;)

相关问题