My table is--
create table mobile
(
id integer,
m_name varchar(20),
cost integer
)
and the values are --
insert into
One of the rare times a CROSS JOIN is applicable:
WITH avgcost as (select round(avg(cost)) as Average from mobile)
SELECT id, m_name as "Mobile Name", cost as Price, Average,
cost-Average as Difference
FROM mobile cross join avgcost
Which will result in:
ID Mobile Name PRICE AVERAGE DIFFERENCE
10 NOkia 100 123 -23
11 Samsung 150 123 27
12 Sony 120 123 -3