When I run this query
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)
I get this error:
column ic.inscount must appear in the GROUP BY clause or be used in an aggregate function
sum), you need to add the other fields to agroup byclause... - sgeddesamountcolumn in your outer query. So yes you do have to usegroup byagain (for both fields)... - sgeddescommon table expressionisn't being used and I'm not completely sure what you're trying to do. You might be better off deleting this post and re-posting your actual question (vs the error that I've already commented on). - sgeddes