I do a statistical page effect is
The database tables that are created are
Solve how to use PHP implementation, thank you!
Reply to discussion (solution)
A SQL command can be completed
@xuzuning
The Great God ... I'm afraid not!
Yes, I can.
I'm a rookie! Completely retwist!
Select Class, COUNT (*) as number, sum (score) as total number, sum (if (Result valid = ' yes ', 1,0) as effective number, sum (if (the result is valid = ' yes ', score, 0) as effective score ...
Don't write, you lazy use, I do not want to type
@xuzuning sum (if (whether the score is valid = ' yes ', 1,0)) This is not an effective number.
Try the group by and have
@xuzuning @jmy454157571
SQL is right, but PHP loop output is not
$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 of people ', T4.totalscore as ' invalid score ' from
(Select T1.class_ as ' class ', t1.totalnum as ' total number ', T1.totalscore as ' total score ', t2.totalnum as ' effective total number ', t2.totalscore as ' effective total score ' 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_ have flag_= ' is ') as T2 on t1.class_=t 2.class_)
as T3
Left joins (select Class_,count (id_) as Totalnum,sum (score_) as Totalscore from score Group by Class_,flag_ have flag_= ' no ') as T4
on T3. ' Class ' =t4.class_ '
$res = $mysqli->query ($sql);
if ($res) {
echo "2222";
}else{
echo "1111";
}
$mysqli->close ();
?>
Output is 1111
This is what happened, $res didn't get the value Ah! Trouble to see where the problem
SQL statements are the right query in MySQL.