如何查询表和输出平均值,总和,位置,

时间:2013-10-30 01:34:31

标签: php mysql

很多伟大的家伙,任何帮助请在php和mysql中是新手我有一个带有以下字段和密码的表'学生'。

id idnumber | Math | English | Geography | Ict | Biology
1  va01       100    80        89          100   82
2  va02       90     79        70          30    76
3  va03       100    100       100         100   90

有些东西让我堆叠是如何通过php查询并从msql输出(Average,Total,Position,out of),结果假设按照高位标记排列。 例如:第一个学生是va03,第二个是va01,第三个是va02,假设是这样的

1: va03  math English Geograph Ict Biology  Average Total  out of
         100  100     100      100 90       98      490    3

2: va01  Math English Geograph Ict Biology  Average Total  out of
         90   79      70       80  76       79      395    3

3: va02  Math English Geograph Ict Biology  Average Total  out of
         90   79      70       30  76       69        345  3

提前谢谢你。

1 个答案:

答案 0 :(得分:0)

我对PHP的帮助不大,但SQL的相当简单......

Select idnumber, math, english, geography, ict, biology,
Average(math + english + geography + ict + biology)/5  as `mAverage`, 
(Select count(*) from student) as `out of `,
math + english + geography + ict + biology as `Total`
From student
Group by idnumber, math, english, geography, ict, biology
order by Average desc;