How to calculate average of a column and then include it in a select query in oracle?

后端 未结 6 603
野性不改
野性不改 2020-12-30 14:55

My table is--

create table mobile
(
  id integer,
  m_name  varchar(20),
  cost integer
)

and the values are --

insert into         


        
6条回答
  •  庸人自扰
    2020-12-30 15:44

    try

    SELECT id, m_name as "Mobile Name", cost as Price,(select avg(cost) from mobile) as Average),
    cost-(select avg(cost) from mobile) as Difference FROM mobile
    group by id,m_name,cost;
    

    if your query is too expensive that way drop me a commend then I'll improve it.

提交回复
热议问题