doulianqi3870 2014-11-27 17:01
浏览 42

如何在具有相同ID的PHP和SQL中添加多个列?

I have two columns in a MySQL table, one called "Total Experience" and one called "id"

Is there a way to add up the value of Total Experience and put it in a variable for all users with the same id?

Example: There are 3 users: Steve, Jack, and Sam

Steve has the id of 1 and Total Experience of 500
Jack has the id of 1 and Total Experience of 400
Sam has the id of 2 and Total Experience of 700

Is there a way to select and add up Steve and Jack's Total Experience in a SQL query, as they have the same id?

  • 写回答

1条回答 默认 最新

  • dsceme82487 2014-11-27 17:04
    关注

    Use GROUP BY to aggregate rows by a column.

    SELECT id, SUM(`Total Experience`) AS experience
    FROM YourTable
    GROUP BY id
    
    评论

报告相同问题?

悬赏问题

  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败