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.
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 AlbumNumberIm supposed to list all albums and the number of tracks on eachI'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 beginningIt makes sense that I am selecting Albums.AlbumTitleI certainly want that field returnedBut 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 |
|
|
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_tracksfrom Albums A join AlbumSongs Son A.AlbumID = S.AlbumIDgroup by A.AlbumTitle[/code]Harsh Athalyehttp://in.linkedin.com/in/harshathalye/ |
|
|
Ziroshima
Starting Member
2 Posts |
Posted - 2014-10-08 : 09:26:11
|
Thank you. |
|
|
|
|
|