简体   繁体   English

在mysql中添加两个列值

[英]adding two column values in mysql

I have two mysql tables 我有两个mysql表

suppose table one name 'marks' 假设表一个名称'标记'

 no   A    B    C    D
 1   10   05   01   04
 2   08   07   10   05
 3   09   05   07   10
 4   07   05   04   10
 5   04   07   06   09
 6   05   09   07   07
 7   09   05   10   06
 8   09   06   06   08
 9   08   06   10   07
10   08   07   04   06

suppose table two name 'results' 假设表两个名称'结果'

in second table I want to put total marks and average marks based on above table. 在第二个表中我想根据上表放置总分和平均分。
(import data from 'marks' table,process it and save it in 'results' table) (从'marks'表导入数据,处理它并将其保存在'results'表中)

So once it filled it must be like this. 所以一旦它填满它必须是这样的。
I want add column A,B,C,D in 'marks' table and put total value in column 'Total' in table 'results' and average by dividing 'Total' column by 4. 我想在'标记'表中添加A,B,C,D列,并将总值放在表'结果'中的'Total'列中,并将'Total'列除以4。

 no   Total    Average
 1     20        5.00
 2     30        7.50   
 3     31        7.75
 4     26        6.50
 5     26        6.50 
 6     28        7.00
 7     30        7.50
 8     29        7.25
 9     31        7.75
10     25        6.25

So how can I fill the 'result' table using mysql query? 那么如何使用mysql查询填充'result'表呢?
Is it possible to do in mysql? 是不是可以在mysql中做?
Thank you 谢谢

Try something like: 尝试类似的东西:

INSERT INTO result (no, total, average)
SELECT no, A+B+C+D, (A+B+C+D)/4
FROM marks

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM