'Complex' MySQL Query
Posted: Fri Oct 02, 2009 11:31 am
This might be simple, haha and i'm being silly anyway.
I have loads of entries in a database, they're batsmen/bowler stats, but for now only batsmen.
Each player will have a unique name, so there might be "Joe Bloggs" and then "Joe Bloggs(2)" but say we use Joe Bloggs as an example. I want to get all the data in the database, group it per name. So say there is 4 entries for Joe Bloggs, 2 for Ashley Lloyd, 3 for Harry Dickens I want to group them to each name and then add up the scores entered.
I'm not explaining this very well am I? But basically there will be lots of entries per player, but I want the get the scores from each entry and ad them up so the db would look like:
Joe Blogs - 14
Joe Blogs - 19
Ashley Lloyd - 30
Joe Blogs - 10
Harry Dickens - 5
Harry Dickens - 10
Ashley LLoyd - 5
Then it would output as:
Joe Blogs - 14 + 19 + 10 (So it would echo 43)
Harry Dickens - 5 + 10 (So display 15)
Ashley Lloyd - 30 + 5 (So display 35).
Get it now? I hope so :/
I think it will need to loop, but I just have no idea how to group them together :/
Thanks!
I have loads of entries in a database, they're batsmen/bowler stats, but for now only batsmen.
Each player will have a unique name, so there might be "Joe Bloggs" and then "Joe Bloggs(2)" but say we use Joe Bloggs as an example. I want to get all the data in the database, group it per name. So say there is 4 entries for Joe Bloggs, 2 for Ashley Lloyd, 3 for Harry Dickens I want to group them to each name and then add up the scores entered.
I'm not explaining this very well am I? But basically there will be lots of entries per player, but I want the get the scores from each entry and ad them up so the db would look like:
Joe Blogs - 14
Joe Blogs - 19
Ashley Lloyd - 30
Joe Blogs - 10
Harry Dickens - 5
Harry Dickens - 10
Ashley LLoyd - 5
Then it would output as:
Joe Blogs - 14 + 19 + 10 (So it would echo 43)
Harry Dickens - 5 + 10 (So display 15)
Ashley Lloyd - 30 + 5 (So display 35).
Get it now? I hope so :/
I think it will need to loop, but I just have no idea how to group them together :/
Thanks!