So let’s say we have a table called phone.
and i need another column to show the average cost of a brand phone
I know i can do something like this:
SELECT brand, AVG (cost)
GROUP BY brand;
and get something like this table:
Can someone help me how i would get this result below using a select sql statement?
You can use avg(cost) over (partition) such as this:
select *, round(avg(cost) over (partition by brand), 2) as avg_cost from phone;