字段数据相加求和,该怎么处理

WBOY
Release: 2016-06-13 13:34:14
Original
1290 people have browsed it

字段数据相加求和
比如:我做一个表“学生成绩表”
字段有:学号、姓名、语文、数学、英语、总分,总共六个字段,现在是有学生比如:学号:1、姓名:张三、语文:65、数学:75、英语:80;学号:2、姓名:李四、语文:60、数学:70、英语:80;学号:3、姓名:王麻子、语文:68、数学:72、英语:85;那么我怎么求他们的总分是多少?还有三个人的数学总分是多少、语文总分是多少、英语总分是多少、和他们的总分和是多少?再拿总分来平均分给他们,这样知道他们的平均分?谢谢!

------解决方案--------------------
select sum(`yuwen`) from cehngjidan where Uid='".$Uid."'";
环绕yuwen两边的,是键盘tab键上面ESC键下面的那个斜点,不是引号什么的
$total=$obj->exec($sqlsum); 这种写法只是返回update,delete语法操作后的更新函数,要用 $obj->query()来取得select语句的结果集
http://cn.php.net/manual/en/pdo.query.php
------解决方案--------------------
由于没看到你类是怎么些的。只能提供原装的程序:
$sql="select sum(`yuwen`) as yuwen_sum from cehngjidan where Uid='".$Uid."'";
$result=mysql_query($sql);
$row=mysql_fetch_assoc($result); 
echo $row['yuwen_sum'];

------解决方案--------------------

PHP code
$sql =
                 
              
              
        
            
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!