Jump to content

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.