Find Average Purchase Value
Easy
You are given the following tables:
attribution table:
user_sessions table:
Find the average value of purchases made through each marketing channel and arrange them in descending order, starting with the channel that has the highest average purchase value. Your output should have the following columns: marketing_channel, avg_purchase_value
SQLSELECT marketing_channel, AVG(purchase_value) AS avg_purchase_value FROM attribution GROUP BY marketing_channel ORDER BY AVG(purchase_value) DESC;
Here is my implementation:
select marketing_channel, AVG(purchase_value) as avg_purchase_value from attribution group by marketing_channel order by avg_purchase_value DESC ;
There is no need to copy and past the line of code for calculating the average into order by, just Alias is enough because going by the order of execution in sql, Always, order by is executed after executing select clause.