My table is--
create table mobile
(
id integer,
m_name varchar(20),
cost integer
)
and the values are --
insert into mobile values(10,'NOkia',100);
insert into mobile values(11,'Samsung',150);
insert into mobile values(12,'Sony',120);
I know how to calculate average on column cost, my code is--
select avg(cost) from mobile;
and the result is 123
But i want to calculate average and then also show the difference.I was able to this but, I am not able to add avg column in the select query--
My code is ---
SELECT id, m_name as "Mobile Name", cost as Price,avg(cost) as Average,
cost-(select avg(cost) from mobile) as Difference FROM mobile
group by id,m_name,cost;
and the output is --
id Mobile Name Price Average Difference
10 Nokia 100 100 -23
11 Samsung 150 150 27
12 Sony 120 120 -3
what I wants is to correct this average column.. I wants this---
id Mobile Name Price Average Difference
10 Nokia 100 123 -23
11 Samsung 150 123 27
12 Sony 120 123 -3
please help...