當我運行此查詢列「ic.inscount」必須出現在GROUP BY子句或聚合函數中使用
WITH install_count_join_date AS (
SELECT
date_trunc('month', join_date) AS date,
COUNT(*) AS "inscountjoin"
FROM
apps202_prod.search
WHERE
join_date >= '2016-06-01'
AND
app_id = 3
GROUP BY
date_trunc('month', join_date)
), install_count AS (
SELECT
DATE(original_timestamp) AS date,
COUNT(*) AS "inscount"
FROM
apps202_prod.search
WHERE
original_timestamp >= '2016-06-01'
AND
app_id = 3
GROUP BY
DATE(original_timestamp)
)
SELECT
date_trunc('month', mr.date) AS "money_revenue_date",
SUM(mr.amount) AS "amt",
ic.inscount AS "install_count"
FROM
mysql_apps202_prod.apps202_prod_money_revenue mr
join install_count ic on date_trunc('month', ic.date) = date_trunc('month', mr.date)
WHERE
date_trunc('month', mr.date) >= '2016-06-01'
AND
mr.app_id = 3
GROUP BY
date_trunc('month', mr.date)
我得到這個錯誤:
column ic.inscount must appear in the GROUP BY clause or be used in an aggregate function
該錯誤是相當自我解釋...因爲你的最終查詢使用聚合('sum'),您需要將其他字段添加到'組by'子句... – sgeddes
我不需要爲該組添加子帳號,因爲我已經在with子句中彙總了它,因爲您在上面的代碼中看到它 –
您正在彙總外部查詢中的「amount」列。所以是的,你必須再次使用'group by'(對於這兩個字段)... – sgeddes