Jump to content

Get avarage from results [php & mysql]


gammele

Recommended Posts

Hi there programmers,

 

I am trying to get the avarage score for a criterium out of the database.

The system is used to give grades to a meeting.

 

My database structure is like this:

 

#Results#

Result_id

Result_overall_percentage

 

#criteriumresult#

Criteriumresult_id

Criteriumresult_link_id (refers to result_id)

Criteriumresult_criterium_id (refers to criterium_id)

Criteriumresult_percentage

 

#criterium

Criterium_id

Criterium_tekst

For example:

 

1 - The employees are well prepared

2 - There was no interruption

 

What i would like to do, is write a query, which collects the avarage score of ID's.

 

//splittetResultIDs = multiple selections

$SelectQuery = mysql_query("
SELECT 
	*
FROM 
	criteriumresult
WHERE 
	Criteriumresult_link_id  IN(".$splittetResultIDs.") 
") or die (mysql_error());

 

I get a lot of results, but i would like to filter unique criteria, and only list them as unique items and with an avarege score.

How can i do this?

 

Link to comment
https://forums.phpfreaks.com/topic/251724-get-avarage-from-results-php-mysql/
Share on other sites

You need to be slightly clearer on what you want.

 

There is an AVG function within MYSQL which will do what you want and you can still have a WHERE clause on it.

 

Eg

 

SELECT AVG(Result_overall_percentage) as Average FROM Results WHERE ........................

 

This will give you a return called  'Average' depending on the conditions you specify in the WHERE clause

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.