14,494 questions
Hi @sghs sh
Try this query.
create table test(Id int,Name varchar(20),Dept int,Season1 int,Season2 int,Season3 int,Season4 int)
insert into test values
(1,'SWER',20,7,6,10,3),
(2,'MARS',30,4,8,7,2);
;with CTE as(
select * from test
unpivot(Amount for Season in(Season1,Season2,Season3,Season4)) t)
select Id,Name,Dept,right(Season,1) as Season,Amount from CTE;
Output:
Best regards,
Percy Tang
If the answer is the right solution, please click "Accept Answer". If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.