November 18, 2008 at 6:26 pm
Hello,
I have a query to select title_id, type, price and average of prices by type from titles in the pubs database. The goal is show all the fields plus the avg(price). I tried with group by clause and not able to get desired result. Could some one help me please?
Thanks
beginner-sql :w00t:
November 18, 2008 at 6:57 pm
Please post what you tried so we can see things like what you tried to GROUP BY. Thanks.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 19, 2008 at 6:26 pm
Hello there,
This is the Task:
Select the title_id, type, and price from the titles table along with an average price for all tables
November 19, 2008 at 6:49 pm
kmohan39 (11/19/2008)
Hello there,This is the Task:
Select the title_id, type, and price from the titles table along with an average price for all tables
Not what I asked for... I want to see the code that you've actually tried... not pseudo code.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 19, 2008 at 7:27 pm
select title_id, type, price, avg(price)
from titles
group by title_id, type, price
order by type
November 19, 2008 at 9:32 pm
SELECT t.Title_ID, t.Type, t.Price, d.AvgPrice
FROM dbo.Titles t
INNER JOIN
(--==== Derived table "d" finds average Price for each Type
SELECT Type, AVG(Price) AS AvgPrice
FROM dbo.Titles
GROUP BY Type) d
ON t.Type = d.Type
--Jeff Moden
Change is inevitable... Change for the better is not.
November 19, 2008 at 9:43 pm
Thank you Jeff Moden
newbie
November 19, 2008 at 10:16 pm
You bet. Thank you for the feedback.
Now you know why I asked to see your query. For more information on how to get better answers quicker on future posts, take a look at the link in my signature line.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy