I am trying to query the original source which contain totals from a category (in this case Vehicles) into the second table.
| Motorcycle | Bicycle | Car |
|---|---|---|
| 1 | 3 | 2 |
Desired Output:
| Vehicle | Quantity |
|---|---|
| Bicycle | 3 |
| Car | 2 |
| Motorcycle | 1 |
Additionally, I need that the Quantity is sorted in descending order like showing above.
So far I have tried to do an Unpivot, but there is a syntax error in the Unpivot function. Is there another way to reach out the same results?
My code so far:
SELECT Vehicle_Name
FROM
(
SELECT [Motorcycle], [Bycycle], [Car] from Data
) as Source
UNPIVOT
(
Vehicle FOR Vehicle_Name IN ([Motorcycle], [Bycycle], [Car])
) as Unpvt