About the table Statistics processing function of php

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.