我在下面有以下PostgreSQL查询。如果我删除一行AND r.type = "long_form"
,它将正常工作。我不确定为什么PostgreSQL不喜欢这一行:
SELECT TRUNC(DATE_PART('day', CURRENT_DATE - r.created_at )/7) AS weeks_ago,
date(min(r.created_at)) AS "Date Start",
date(max(r.created_at)) AS "Date End",
count(*) as "Reviews in Cohort",
AVG(has_note::int) as "Reviews w 1 or more Notes Ratio"
FROM (SELECT r.id, r.created_at,
( MAX(rn.note) IS NOT NULL ) as has_note
FROM reviews f JOIN
reviewss_notes rn
ON r.id = rn.review_id
WHERE r.completed_at IS NOT NULL
AND r.created_at > '2019-01-01'
AND r.type = "long_form"
GROUP BY r.id
) f
GROUP BY weeks_ago
ORDER BY weeks_ago DESC;
这是导致问题的查询行:
AND r.type = "long_form"
表的设计包括以下列:
我在这里做什么错了?
答案 0 :(得分:1)
检查引号字符...
AND r.type = 'long_form'
使用单引号表示字符串常量。