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
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

Link to comment
Share on other sites

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.