简体   繁体   English

SQL查询计算总计

[英]SQL Query Calculate Total

So let's say I have data in my query like this: 假设我的查询中有这样的数据:

Name: |  Cost:
Oliver     20
Oliver     3
Oliver     2
Sarah      100
Sarah      7

How would I go about merging the data for each person into one row and having a total cost? 我该如何将每个人的数据合并为一行并产生总成本?

you can use group by and sum() 您可以使用group by和sum()

select name, sum(cost)
from your_table
group by  name 

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

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