Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have total score for 2 years which is 2022 and 2023 with same name. My problems is the total score calculated all the year.

What I have tried:

$sectionb_total_score = 0;
	$Year = date('Y');
	$mySQL2 = 'SELECT COUNT(A.id) as TotalID, SUM(A.total_score) as TotalScore, A.year_assessment FROM assessment_technical A INNER JOIN assessment_year B ON A.assessment_year_id = B.id WHERE A.year_assessment = B.year_assessment AND A.staff_id =' .$data['staff_id'] ;
	$result2 = mysql_query($mySQL2);
	if ($result2){
		if (mysql_num_rows($result2) > 0){
		$row2 = mysql_fetch_assoc($result2);
		$sectionb_total_score = $row2['TotalScore'] / $row2['TotalID'];
		}
	}
Posted
Updated 28-Aug-22 19:02pm

1 solution

Try using a GROUP BY clause: SQL GROUP BY Statement[^]
 
Share this answer
 
Comments
OriginalGriff 30-Aug-22 1:02am    
"it did not work" is one of the error reports we get quite often, and it's always completely useless - it tells us nothing about your problem other than "I have a problem" and we knew that because you are asking a question!

What did it do that you didn't expect, or not do that you did?
When did it do it?
Are there any error messages?
What did you do to make it do that?
What have you tried to do to find out why?
What were the results?

These are all questions we need an answer to - or we can't help you at all!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900