คำตอบ SQL stored procedure to find the number of people within a group of a particular year

  • 23 พฤษภาคม 2555 4:56
     
      มีโค้ด

    I am wanting to create a stored procedure that accepts the team name and year and returns the number of players in that particular team for that particular year. I am working with MYSQL and listed below are the tables I am using:

    Person     (personID, name, phone, email, year)
    Player    
    (personID, dateOfBirth, school)
    playerTeam
    (personID, teamID)
    Team      
    (teamID, teamName, ageGroup)

    So far I have tried joining the tables and couting the personID only where teamName and Person.year = the input parameters but to no avail. Any ideas?

ตอบทั้งหมด

  • 23 พฤษภาคม 2555 6:45
    ผู้ตอบ
     
     คำตอบ

    This is SQL Server forum not MySQL.. but can you try

    SELECT <columns> FROM Person P JOIN PayerTeam PT

    ON P.PersonID=PT.PersonID join Team T ON T.TeamID=PT.TeamID

    WHERE Year=@Year AND teamname =@TeamName


    Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/

    • เสนอเป็นคำตอบโดย Dimitri C 23 พฤษภาคม 2555 6:49
    • ทำเครื่องหมายเป็นคำตอบโดย amber zhangEditor 30 พฤษภาคม 2555 8:10
    •  
  • 23 พฤษภาคม 2555 7:34
     
     

    select<ColumnName>  from Person per
    inner join playerName ply on ply.PersonID = per.PersonID
    inner join Team tm on tm.teamID = ply.teamID
    where per.years =<<Year>> and tm.TeamName = <<TeamName>>

    Please insert the team name in the team table and join the Team name in the where condition.

    select<ColumnName> per.PersonID from Person per
    inner join playerName ply on ply.PersonID = per.PersonID
    inner join Team tm on tm.teamID = ply.teamID
    where per.years =2005 and tm.TeamName = 'a'


    With Thanks and Regards Sambath