Given that Store
table contains Revenue
and Category
column, to find out what is the revenue by category I can do a SQL query similar to something below.
Store table:
+------+---------+----------+
| ID | Revenue | Category |
+------+---------+----------+
| 1 | 60 | Toy |
| 2 | 50 | Food |
| 3 | 40 | Food |
| 1 | 6 | Drinks |
| 1 | 5 | Drinks |
+------+---------+----------+
SELECT SUM(Revenue), Category
FROM Department
GROUP BY Category
I would then get the following result below.
+---------+----------+
| Revenue | Category |
+---------+----------+
| 60 | Toy |
| 90 | Food |
| 11 | Drinks |
+---------+----------+
However, would it be possible to transpose the category column such that I am able to get the following results below?
+-------------+--------------+----------------+
| Toy_Revenue | Food_Revenue | Drinks Revenue |
+-------------+--------------+----------------+
| 60 | 90 | 11 |
+-------------+--------------+----------------+