作者:用户q4oaa53j5h | 来源:互联网 | 2022-12-02 16:35
我有一张员工桌.此表有三列:CustomerName
,Role
,和Salary
.在CustomerName
User1列中出现多次,但我只想要一行总薪水为User1.下面我粘贴了一些样本数据供参考.
+--------------+------------+--------+
| CustomerName | Role | Salary |
+--------------+------------+--------+
| User1 | Design | 100 |
| User2 | Developer | 100 |
| User1 | Design | 100 |
| User3 | Programmer | 100 |
| User1 | Design | 100 |
+--------------+------------+--------+
输出应该像:
+--------------+------------+----------+
| CustomerName | Role | Salary |
+--------------+------------+----------+
| user1 | Design | 300 |
| user2 | Developer | 100 |
| user3 | Programmer | 100 |
+--------------+------------+----------+
我想要User1的工资总额.怎么能实现这一目标?
1> Fahmi..:
使用group by聚合
select customername,role, sum(salary) as salary
from tablename
group by customername, role