简体   繁体   中英

adding two column values in mysql

I have two mysql tables

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)

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.

 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?
Is it possible to do in 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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