Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query Help (Homework)

Author  Topic 

Ziroshima
Starting Member

2 Posts

Posted - 2014-10-07 : 20:15:00
I am stuck on a homework question: I have two relevant tables:AlbumSongs, with SongId, AlbumID, TrackNumber, and TrackLength. And Albums, with AlbumID, AlbumTitle, AlbumYear, BandID, and AlbumNumber
Im supposed to list all albums and the number of tracks on each
I'm having a hard time thinking in sql and understanding what is going on.
My query starts out as SELECT DISTINCT Albums.AlbumTitle, Count(*)
But Im not sure this is even the right beginning
It makes sense that I am selecting Albums.AlbumTitle
I certainly want that field returned
But Im not sure how to specify that I just want my second column to be the number of columns that have a tracknumber with that AlbumID from AlbumSongs

sunder.bugatha
Yak Posting Veteran

66 Posts

Posted - 2014-10-08 : 03:38:34
Can you paste sample data from both tables?

Hema Sunder
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2014-10-08 : 03:45:10
[code]Select A.AlbumTitle, count(S.TrackNumber) as num_of_tracks
from Albums A join AlbumSongs S
on A.AlbumID = S.AlbumID
group by A.AlbumTitle[/code]

Harsh Athalye
http://in.linkedin.com/in/harshathalye/
Go to Top of Page

Ziroshima
Starting Member

2 Posts

Posted - 2014-10-08 : 09:26:11
Thank you.
Go to Top of Page
   

- Advertisement -