MS SQL中的聚合函数问题 [英] aggregate function problem in MS SQL

查看:74
本文介绍了MS SQL中的聚合函数问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一张像
的桌子
tableA
----------------------------
Nam Amount
---------------------------
管理员200
史密斯300
管理员400
史密斯100
管理员200

我想像这样显示这张桌子
tableA
----------------------------
Nam Amount
---------------------------
管理员800
史密斯400

注意:所有都是MSSQL表

在此先感谢

Suppose I have one table like

tableA
----------------------------
Nam Amount
---------------------------
Admin 200
Smith 300
Admin 400
Smith 100
Admin 200

I want to show this table like
tableA
----------------------------
Nam Amount
---------------------------
Admin 800
Smith 400

NB: all are MSSQL tables

Thanks in advance

推荐答案

您需要按名称分组,然后选择名称和金额总和.
顺便说一下,这很容易通过Google进行搜索:
You need to group by name, and select on name and the sum of amount.
This is easily googleable by the way:
http://www.google.com/search?q=group+by+with+sum&sourceid=ie7&rls=com.microsoft:en-gb:IE-SearchBox&ie=&oe=[^]


家庭作业?
无论如何,答案就在这里:
Homework?
Any way, here goes the answer:
SELECT [Name],SUM(Amount) 
FROM tableA
Group By [Name]


这篇关于MS SQL中的聚合函数问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆