OBAID
OBAID

Reputation: 1539

how to write query for this reuslt

I have a employee table having column (empno,enme,salary,deptno)
I want to write a query which displays the following table:containing first column

,second column

Any one please help me how to write query for this scenario..?

Upvotes: 0

Views: 70

Answers (1)

Shukri Gashi
Shukri Gashi

Reputation: 535

A have simulated your situation with a table variable and below is the result

DECLARE @table TABLE (empno int,ename VARCHAR(100),salary DECIMAL(18,2),deptno int)
INSERT INTO @table SELECT 1,'shuki',450,100
INSERT INTO @table SELECT 2,'arban',500,100
INSERT INTO @table SELECT 3,'alamet',300,200
INSERT INTO @table SELECT 4,'andrea',150,200
INSERT INTO @table SELECT 5,'florim',450,200

SELECT deptno,SUM(CASE when ename LIKE 'A%' THEN salary ELSE 0 END ) SalaryEmpWithA,SUM(salary) TotalSalary FROM @table
GROUP BY deptno

Output is:

deptno  SalaryEmpWithA  TotalSalary
100     500.00          950.00
200     450.00          900.00

Upvotes: 1

Related Questions