How to unpivot multiple columns in same table

How to unpivot multiple columns in same table

I have a table with below structure, I need to unpivot the output so that I get one row per ID per PARAMETER and it's corresponding RATINGS

I have a table with below structure, I need to unpivot the output so that I get one row per ID per PARAMETER and it's corresponding RATINGS

create table RATINGS(ID INT,PARAMETER1 INT,PARAMETER2 INT,PARAMETER3 INT,PARAMETER4 INT)
insert into RATINGS values(1000,1,3,2,1)
insert into RATINGS values(1002,2,3,3,2)
insert into RATINGS values(1007,3,3,2,1)
insert into RATINGS values(1015,1,3,1,3)
insert into RATINGS values(1019,3,2,1,1)

expected output:

ID    PARAMETERS RATING
1000  PARAMETER1  1
1000  PARAMETER2  3
1000  PARAMETER3  2
1000  PARAMETER4  1
1002  PARAMETER1  2
1002  PARAMETER2  3
1002  PARAMETER3  3
1002  PARAMETER4  2
1007  PARAMETER1  3
1007  PARAMETER2  3
1007  PARAMETER3  2
1007  PARAMETER4  1
1015  PARAMETER1  1
1015  PARAMETER2  3
1015  PARAMETER3  1
1015  PARAMETER4  3
1019  PARAMETER1  3
1019  PARAMETER1  2
1019  PARAMETER1  1
1019  PARAMETER1  1

Later, I also need to filter so that I get only those rows that have ratings 1 and 2. So the output then must be

ID    PARAMETERS RATING
1000  PARAMETER1  1
1000  PARAMETER3  2
1000  PARAMETER4  1
1002  PARAMETER1  2
1002  PARAMETER4  2
1007  PARAMETER3  2
1007  PARAMETER4  1
1015  PARAMETER1  1
1015  PARAMETER3  1
1019  PARAMETER1  2
1019  PARAMETER1  1
1019  PARAMETER1  1

I am able to get the first two ID and PARAMETERS column using below query:

select ID,[parameters] from RATINGS
unpivot
(
[value] for [PARAMETERS] in (PARAMETER1,PARAMETER2,PARAMETER3,PARAMETER4)
) unpvt

OUTPUT:

**ID**      **PARAMETERS**
1000    PARAMETER1
1000    PARAMETER2
1000    PARAMETER3
1000    PARAMETER4
1002    PARAMETER1
1002    PARAMETER2
1002    PARAMETER3
1002    PARAMETER4
1007    PARAMETER1
1007    PARAMETER2
1007    PARAMETER3
1007    PARAMETER4
1015    PARAMETER1
1015    PARAMETER2
1015    PARAMETER3
1015    PARAMETER4
1019    PARAMETER1
1019    PARAMETER2
1019    PARAMETER3
1019    PARAMETER4

Could someone please let me know how to get the RATING column

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

SQL Server Tutorial For Beginners - Learn MS SQL Server with Examples

SQL Server Tutorial For Beginners, Microsoft SQL Server Tutorial, SQL Server Training. Microsoft SQL Server explains all the fundamentals of MS SQL Server with examples. What is DBMS? What is SQL? What is SQL Server? SQL Server Installation

What are the differences between Standard SQL and Transact-SQL?

In this article, we'll explain syntax differences between standard SQL and the Transact-SQL language dedicated to interacting with the SQL

Build a CRUD App with ASP.NET Core 2.2 and SQL Server

​ I’ve always said that you can tell a lot about a person by the kind of music they listen to. Don’t tell me you haven’t had serious doubts about whether you can be friends with someone when you find out that they like a particular band or artist. In that spirit, I created *JudgeMyTaste*, an ASP.NET Core web application where people can enter their favorite band or artist so that people on the Internet can judge them openly. ​ The combination of ASP.NET and SQL Server is probably the most common pairing in the enterprises that use ASP.NET. With ASP.NET Core and SQL Server both being cross-platform, you don’t *have* to run this combination on Windows anymore! I’ll show you how to create a basic CRUD application using ASP.NET Core 2.2 and SQL Server 2017. I’ll be running on Linux, but with the free tools used here, it won’t matter what operating system you’re using! ​ The tools I’ll be using that are available for all platforms are: * SQL Server 2017 (I’ll be running on Ubuntu 18.04) * Visual Studio Code * Azure Data Studio * ASP.NET Core 2.2 ​ Once you’ve got all the tools installed for your platform, let’s rock and roll! ​ ​ ​ ## Scaffold Your ASP.NET Core 2.2 Application ​ No matter the platform you’re on, the ```dotnet``` CLI is available. The commands used here should be the same for everyone. To scaffold the ASP.NET Core 2.2 MVC application, create a new folder for it: I’ve always said that you can tell a lot about a person by the kind of music they listen to. Don’t tell me you haven’t had serious doubts about whether you can be friends with someone when you find out that they like a particular band or artist. In that spirit, I created JudgeMyTaste, an ASP.NET Core web application where people can enter their favorite band or artist so that people on the Internet can judge them openly.