时间:2021-07-01 10:21:17 帮助过:20人阅读
$sql =<<< SQL create table `学生成绩表` ( `学号` int, `姓名` varchar(10), `语文` int default 0, `数学` int default 0, `英语` int default 0, `总分` int default 0, PRIMARY KEY (`学号`) ) SQL; //mysql_query($sql) or die(mysql_error());//执行一次后就注释掉 $sql = <<< SQL insert into `学生成绩表` values (1, '张三', 65, 75, 80, 0), (2, '李四', 60, 70, 80, 0), (3, '王麻子', 68, 72, 85, 0) SQL; //mysql_query($sql) or die(mysql_error());//执行一次后就注释掉 //mysql_query('update `学生成绩表` set `总分`=`语文`+`数学`+`英语`');//执行一次后就注释掉 $sql =<<< SQL select sum(`总分`) as `总分合计`, avg(`总分`) as `总平均分`, sum(`语文`) as `语文总分`, avg(`语文`) as `语文平均分`, sum(`数学`) as `数学合计`, avg(`数学`) as `数学平均分`, sum(`英语`) as `英语合计`, avg(`英语`) as `英语平均分` from `学生成绩表` SQL; $rs = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($rs); print_r($row);