Jump to content

SUM and GROUP BY help


ded

Recommended Posts

I need some help creating a query

 

My database has the following fields:

firstname

lastname

games

points

average

event

year

 

Each player can have 1 - 8 records at this point

 

I want to be able to GROUP BY firstname and lastname combined.  I want to sort by the combined average.  So basically I will need to sum games and points and then divide them to create the overall average.

 

 

Link to comment
https://forums.phpfreaks.com/topic/241337-sum-and-group-by-help/
Share on other sites

Examples records:

First

Last

games

points

average

event

year

John

Doe

17

904

53.18

ABDA Nationals

2010

John

Doe

21

1132

53.90

PA States

2010

John

Doe

8

414

51.75

PA States

2009

 

 

I put in this code

SELECT * , SUM(`games`) , SUM(`points`) , SUM(`average`) 
FROM `averages` 
GROUP BY `lastname` ,`firstname` 
ORDER BY `lastname` ,`firstname` 
LIMIT 0 , 9999

 

This shows the following

 

First

Last

SUM(`games`)

SUM(`points`)

SUM(`average`)

John

Doe

46

2450

158.83

 

For the SUM(`average`), I need it to show 53.26 which is 2450/46.

I need it to show the following:

First

Last

SUM(`games`)

SUM(`points`)

SUM(`average`)

John

Doe

46

2450

53.26

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.