title: How to calculate average of a column and then include it in a select query in oracle?
body: <p>My table is--</p>
  
  <pre><code>create table mobile
  (
    id integer,
    m_name  varchar(20),
    cost integer
  )
  </code></pre>
  
  <p>and the values are --</p>
  
  <pre><code>insert into mobile values(10,'NOkia',100);
  insert into mobile values(11,'Samsung',150);
  insert into mobile values(12,'Sony',120);
  </code></pre>
  
  <p>I  know how to calculate average on column cost, my code is--</p>
  
  <pre><code> select avg(cost) from mobile;
  </code></pre>
  
  <p>and the result is <strong>123</strong></p>
  
  <p>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--</p>
  
  <p>My code is ---</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>and the output is --</p>
  
  <pre><code>id      Mobile Name   Price  Average  Difference 
  10      Nokia         100    100      -23
  11      Samsung       150    150       27
  12      Sony          120    120      -3
  </code></pre>
  
  <p>what I wants is to correct this average column.. I wants this---</p>
  
  <pre><code>id      Mobile Name  Price  Average  Difference 
  10      Nokia       100     123     -23
  11      Samsung     150     123      27
  12      Sony        120     123      -3
  </code></pre>
  
  <p>please help...</p>