sripriya
sripriya

Reputation: 131

how to find particular Employee total amount

I have an employee table. This table has three columns: CustomerName, Role, and Salary. In the CustomerName column User1 appears many times but I only want one row with the total salary of User1. Below I pasted some sample data for reference.

+--------------+------------+--------+
| CustomerName |    Role    | Salary |
+--------------+------------+--------+
| User1        | Design     |    100 |
| User2        | Developer  |    100 |
| User1        | Design     |    100 |
| User3        | Programmer |    100 |
| User1        | Design     |    100 |
+--------------+------------+--------+

Output should be like:

+--------------+------------+----------+
| CustomerName |     Role   |  Salary  |
+--------------+------------+----------+
| user1        | Design     |      300 |
| user2        | Developer  |      100 |
| user3        | Programmer |      100 |
+--------------+------------+----------+

I want the total amount of User1's salary. How can this be achieved?

Upvotes: 1

Views: 67

Answers (2)

Vijunav Vastivch
Vijunav Vastivch

Reputation: 4211

For user1

select customername,role,sum(salary) from yourtable where customername='user1' group by customername,role

Upvotes: 2

Fahmi
Fahmi

Reputation: 37483

use aggregation with group by

select customername,role, sum(salary) as salary
from tablename
group by customername, role

Upvotes: 5

Related Questions