Mr Chris Posted November 2, 2007 Share Posted November 2, 2007 Hi All, I was wondering if someone could help me with a query. I am trying to count appearances made for a football match. Now as you can see below a football team has - eleven players - A maximum of Five subs and no minimum subs - And three out of those five subs can be used So from the below you can see that each player_id from player one to eleven has been given a used sub value of 1. Then with my four substitutes (there was not a fifth named for this match) each used sub has a value of 1 as well. So what I want to do is count each player_id for each report in my database where they have a used_sub value of 1 next to them. How can I do this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/75795-solved-help-with-a-query-please/ Share on other sites More sharing options...
fenway Posted November 2, 2007 Share Posted November 2, 2007 Not sure I understand why you can't simply check that field directly... Quote Link to comment https://forums.phpfreaks.com/topic/75795-solved-help-with-a-query-please/#findComment-383613 Share on other sites More sharing options...
Mr Chris Posted November 2, 2007 Author Share Posted November 2, 2007 Thanks, Basically I have many records in this database for match_id=1, match_id=2 etc. Then I want to produce an apperances table ie count how many times player_id=33 appears in this table or player_id=34 and count the number of used_sub's that player has made? Thanks Chris Quote Link to comment https://forums.phpfreaks.com/topic/75795-solved-help-with-a-query-please/#findComment-383710 Share on other sites More sharing options...
fenway Posted November 2, 2007 Share Posted November 2, 2007 What's the relationship between 33 and 34 in your example? Why not the subs of 33? Quote Link to comment https://forums.phpfreaks.com/topic/75795-solved-help-with-a-query-please/#findComment-383717 Share on other sites More sharing options...
Mr Chris Posted November 2, 2007 Author Share Posted November 2, 2007 Thanks, sorry if i'm not being clear. Right there is no relationship between them. Basically each player_id corresponds to a players name in the database in another table ie: player_id=33 - Mike West So basically in the above table (the jpg image) I'd like to loop through all the records and get each unique player_id. Then i'd like to do a count on each row in the used_subs column to see how many appearances they have made throughout the season. Is this possible? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/75795-solved-help-with-a-query-please/#findComment-383733 Share on other sites More sharing options...
fenway Posted November 2, 2007 Share Posted November 2, 2007 So SUM the used_subs for each player_id? Quote Link to comment https://forums.phpfreaks.com/topic/75795-solved-help-with-a-query-please/#findComment-383738 Share on other sites More sharing options...
Mr Chris Posted November 2, 2007 Author Share Posted November 2, 2007 Yes that's it thanks.what would the query be please? Quote Link to comment https://forums.phpfreaks.com/topic/75795-solved-help-with-a-query-please/#findComment-383744 Share on other sites More sharing options...
fenway Posted November 2, 2007 Share Posted November 2, 2007 SELECT player_id, SUM( used_subs ) FROM yourTable GROUP BY player_id Quote Link to comment https://forums.phpfreaks.com/topic/75795-solved-help-with-a-query-please/#findComment-383764 Share on other sites More sharing options...
Mr Chris Posted November 2, 2007 Author Share Posted November 2, 2007 Magic - thank you! Quote Link to comment https://forums.phpfreaks.com/topic/75795-solved-help-with-a-query-please/#findComment-383905 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.