What is the result of making a statistics page for php to process table statistics?
The created database table is
How can I solve this problem using php? thank you!
Reply to discussion (solution)
One SQL command can be completed.
@ Xuzuning
Great God ...... I'm afraid I can't do it!
Indeed, one item can be added step by step.
I'm a Cainiao! No effort!
Select class, count (*) as number of people, sum (score) as total score, sum (if (whether the score is valid = 'Yes',) as valid number of people, sum (if (whether the score is valid = 'yes', score, 0) as valid score ........
I don't want to type either.
@ Xuzuning sum (if (whether the score is valid = 'yes',) does not calculate the number of valid students
Try group by and having.
@ Xuzuning @ jmy454157571
SQL is correct, but Php cannot output cyclically
$ Mysqli = new mysqli ("localhost", "root", "", "car_insure ");
$ Mysqli-> set_charset ("utf8 ");
If ($ mysqli-> connect_error ){
Die ("connection failed". $ mysqli-> conect_error );
}
$ SQL = "select t3. *, t4.totalNum as 'invalid total number', t4.totalScore as 'invalid total rating' from
(Select t1.class _ as 'class', t1.totalNum as 'total number', t1.totalScore as 'total rating', t2.totalNum as 'total valid number', t2.totalScore as 'total effective rating' from (select class _, count (id _) as totalNum, sum (score _) as totalScore from score group by class _) as t1 left join (select class _, count (id _) as totalNum, sum (score _) as totalScore from score group by class _, flag _ having flag _ = 'Yes') as t2 on t1.class _ = t2.class _)
As t3
Left join (select class _, count (id _) as totalNum, sum (score _) as totalScore from score group by class _, flag _ having flag _ = 'no ') as t4
On t3. 'class' = t4.class _"
$ Res = $ mysqli-> query ($ SQL );
If ($ res ){
Echo & quot; 2222 & quot ";
} Else {
Echo & quot; 1111 & quot ";
}
$ Mysqli-> close ();
?>
The output is 1111
What's the problem? $ res didn't get the value! What's the problem?
The SQL statement is correct in Mysql.