I want to calculate the median of revenue but show the following error and I don’t understand why:
Column ‘finance.revenue’ is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
This is my code:
with footwear as (
select
description,
revenue
from
info i
inner join finance f on i.product_id = f.product_id
where
(description like '%shoe%'
or description like '%trainer%'
or description like '%foot%')
and description is not null
)
select
count(*) as num_of_products,
percentile_disc(0.5) within group (order by revenue) over() as median_clothing_revenue
from
info i
inner join finance f on i.product_id = f.product_id
where
i.description not in (select description from footwear);
New contributor
Channi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4