首页 > 解决方案 > 如何让这个查询在 postgresql 上工作?

问题描述

有谁知道如何调整这个查询以便它在 postgresql 中工作?add_months 函数显然不存在。非常感谢!

WITH monthly_activity AS (SELECT date_trunc('month', "Date"::date) AS "month", "Company ID"
FROM "DWH_rollup".appointments_totals)

SELECT last_month."month" + add_months(last_month."month", 1), COUNT(DISTINCT last_month."Company ID")
FROM monthly_activity last_month
JOIN monthly_activity this_month
ON this_month."Company ID" = last_month."Company ID" 
AND this_month."month" = add_months(last_month."month", 1)
WHERE this_month."Company ID" is NULL
GROUP BY 1

标签: postgresqlpostgresql-9.3

解决方案


推荐阅读