Pivot SQL SERVER (1 Viewer)

zezo2021

Member
Local time
Today, 19:30
Joined
Mar 25, 2021
Messages
381
Hello

SQL SERVER not access
Table Structure
/
employee name
Department
Salary
City

the table will be full of data


------------------------------
Pivot Table Result will be like this:
department Alabama Arkansas Georgia
IT 100000 50000 6000
Hr 500500 5500 6655


I want to make a pivot in SQL sum salary based on department

What is SQL code
 

CJ_London

Super Moderator
Staff member
Local time
Today, 18:30
Joined
Feb 19, 2013
Messages
16,614
Have you tried googling?

a quick google returns many links - this one for example
 

zezo2021

Member
Local time
Today, 19:30
Joined
Mar 25, 2021
Messages
381
Have you tried googling?

a quick google returns many links - this one for example
Code:
SELECT
  [city],
  [HR],
  [IT]
FROM (
  SELECT
    [city],
    [department],
    sum([salary]) as Salary
  FROM dbo.emp
  GROUP BY [city],[department]
) AS myData
PIVOT (
  sum(myData.[Salary])
  FOR myData.department IN ([HR], [IT])
) AS mypivot

the result (y)
 

Users who are viewing this thread

Top Bottom