【问题标题】:How to sum of two column into third column for all rows如何将所有行的两列总和为第三列
【发布时间】:2013-11-09 03:57:26
【问题描述】:

如何将两列相加到第三列或所有行的输出中

order_id  english maths grand_total 
   1         10      10         20
   2         20      5          25
   3         10      10         20

我运行此查询“从表中选择 sum(english+maths)as grand_total”
结果是

grand_total
   20 

我只得到第一行而不是所有行如何获得一列中所有行的总和

【问题讨论】:

    标签: php mysql


    【解决方案1】:

    试试这个查询:

    select order_id, english, maths, english + maths as grand_total from table
    

    不需要聚合函数,因为您不希望以任何方式对数据进行分组。

    【讨论】:

    • 可能还有其他问题。诸如加法之类的算术运算与字符排序无关:)
    • 此警告显示在我的 sql 查询 #1064 - 您的 SQL 语法中有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取正确的语法,以便在 'english+maths as total from table 附近使用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-21
    • 1970-01-01
    • 2011-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多