Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Pivot unpivot
DECLARE @table table (Agent varchar(20), Country varchar(20), Amount int) INSERT INTO @table SELECT 'Suman', 'INDIA', 1000 Union all SELECT 'Suman', 'US', 1200 Union all SELECT 'Saurav', 'INDIA', 800 Union all SELECT 'Saurav', 'US', 900 Union all SELECT 'Saurav', 'US', 900 SELECT * from @table SELECT Agent, INDIA, US FROM @table PIVOT ( SUM(Amount) FOR Country IN (INDIA, US) ) p SELECT Agent, Country, Amount FROM ( SELECT Agent, INDIA, US FROM @table PIVOT ( SUM(Amount) FOR Country IN (INDIA, US) ) p ) ur UNPIVOT ( Amount FOR Country IN (INDIA, US) ) UP
run
|
edit
|
history
|
help
0
Extracting Id No
FERNANDA_BD_Registro_De_Estudiantes
Demo
jueves
Q2_15min
Max from multiple columns
Running Total
Task_7_Final
Customer_Orders
Window Functions - ROW_NUMBER()