How to add column values in mysql

前端 未结 7 1999
醉话见心
醉话见心 2020-12-09 15:37

This is my table data Student

\"enter

And this is my query --

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 16:18

    The sum function in MySQL works in the sense that it gives you the sum of values in a column from your select statement. If you need to sum values from a row in your query, then just use plus (+) What you need is this query :

    SELECT id, (`maths` +`chemistry`+`physics`) AS `total`, `maths`, `chemistry`, `physics`
    FROM `student`;
    

    This will give you the results you need.

提交回复
热议问题