var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: Query help
I have a simple
"CD" Table (ID, CD_Name, Cost)
it consists of 6 different cds.
I am trying to write a query that lists the name and cost of each cd. and i wish to add a column that compares the cost to the average cost. i.e difference between cost and AVG cost of all cds.
currently i have.
but no luck
select cd_name, cost, avg(cost) - cost as AVG_Difference
group by cost, cd_name
any guidance would be appreciated
You might try with something like this:
SELECT x.cd_name, x.cost, x.avg_cost - x.cost avg_difference
FROM (SELECT cd_name, cost, (SELECT AVG(cost) FROM CD) avg_cost
yeah, the above query works well...
an easier way is-
this will work too...
SELECT cd_name, cost, (SELECT AVG(cost) FROM cd)-cost AS AVG_difference
GROUP BY cost,cd_name;