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 |
|
java_lang
Starting Member
3 Posts |
Posted - 2007-11-29 : 16:16:45
|
| I found a tutorial website for SQL which is quite good for beginner like me. http://www.upriss.org.uk/db/22001.htmlclick : On-line SQL, and thenRegistered Account (you can use any email address), it allows you to use the site 11 days, then you will recieve an email for extension.It provides tutorial information which you can find out how to do the questions. However you cannot find the answers if you don't know how to do it. There have 5 tutorial exercises. You will have two Assessment Questions after finished each exercise (start from tutorial 2). It is valuable to try if you are beginner and want to challenge yourself.I've done most questions. But I dont know how to do the last two Assessment questions. Any people can help me here?The first question:**"List the band name and the number of players for the band whose number of players is greater than the average number of players in each band."**[It is musician database which have 9 tables, I put the relative tables here:]1st Table :SELECT * from Band BAND_NO BAND_NAME BAND_HOME BAND_TYPE B_DATE BAND_CONTACT1 ROP 5 classical 1-Jan-30 112 AASO 6 classical 103 The J Bs 8 jazz 124 BBSO 9 classical 215 The left Overs 2 jazz 86 Somebody Loves this 1 jazz 67 Oh well 4 classical 38 Swinging strings 4 classical 79 The Rest 9 jazz 162nd Table:SELECT * from Plays_inBAND_ID PLAYER1 11 31 41 51 61 71 82 102 122 132 142 152 172 183 193 204 214 224 235 256 266 277 17 47 67 87 287 298 148 158 28The keys to link two tables are :band (band_id)plays_in (band_no): ** it means "band_id" = "band_no" **My code can find all band include zero player band:However, I dont know how to do for "number of players is greater than the average number of players in each band"I've tried different methods, the last one is the following code, but it doesn't worked. SELECT band.band_name, count(player)from band, plays_inwhere band.band_no = plays_in.band_id(+) group by band.band_name having count(player) > ( SELECT avg(count(player)) from player_in group by band_id;Question 2:Give a list of musicians associated with Glasgow. Include the name of the musician and the nature of the association - one or more of "LIVES_IN", "BORN_IN", "PERFORMED_IN" AND "IN_BAND_IN". Musicians who have more than one association with Glasgow should be listed more than once, for example: Jeff Dawn IN_BAND_IN Jeff Dawn LIVES_IN The ER Diagram for Musician is in http://db.grussell.org/ermusician.htmlThe second question is much difficult. It requests 1) musician is associated with Glasgow2) shows the musicians' information like "LIVES_IN", "BORN_IN", "PERFORMED_IN" AND "IN_BAND_IN" 3) the musician names may be appear more than once.Who want to take this challenges meanwhile teaching this junior self learner, I am looking forward to hearing from you soon.rgdsAnnie |
|
|
srimathi.mani
Starting Member
3 Posts |
Posted - 2007-11-30 : 02:42:43
|
| Hey,This query will return you the band name and the number of players for the band whose number of players is greater than the average number of players in each bandselect band.BAND_NO,band.BAND_NAME,band.BAND_TYPEfrom Bandinner joinplays_in on Band.BAND_NO = Plays_in.BAND_IDwhere plays_in.PLAYER > (SELECT AVG(Player)from Plays_in)RegardsSrimathi |
 |
|
|
java_lang
Starting Member
3 Posts |
Posted - 2007-11-30 : 15:57:23
|
| hi SrimathiThank you for your code. However the query is just request 1) the band name 2) the number of players in band is greater than average number of players in other bands.List the band name and the number of players for the band whose number of players is greater than the average number of players in each band.I found the answer manually BAND NAME NUMBER OF PLAYER AASO 7 ROP 7 Ohwell 6There have 9 bands and one of them has no player in the band. The total players in 9 bands are 31, so the average player is 3.4444444I found 9 bands including the 0 players one, but dont know how to compare the average players |
 |
|
|
java_lang
Starting Member
3 Posts |
Posted - 2007-11-30 : 16:37:09
|
hi Srimathi,I know why your answer is incorrected, because you compared the wrong field.As per my understand: PLAYER is the Performer Number (means performer ID)BAND_NO is the band ID which the performer Number plays in.I cannot any table to tell me how the exactly players in each band, so we have to count how many perf_no and in band_no My code can found the band name and number of player of each band,but I dont know how to compare with average players in bandsquote: SELECT band.band_name, count(player)from band, plays_inwhere band.band_no = plays_in.band_id(+)
quote: Originally posted by java_lang hi SrimathiThank you for your code. However the query is just request 1) the band name 2) the number of players in band is greater than average number of players in other bands.List the band name and the number of players for the band whose number of players is greater than the average number of players in each band.I found the answer manually BAND NAME NUMBER OF PLAYER AASO 7 ROP 7 Ohwell 6There have 9 bands and one of them has no player in the band. The total players in 9 bands are 31, so the average player is 3.4444444I found 9 bands including the 0 players one, but dont know how to compare the average players
|
 |
|
|
|
|
|
|
|