-- Pivot tables are the transformation of table data from rows to columns. 
-- Pivot tables are really useful for data analysis to get insights about 
-- the data because they allow you to display row values as 
-- columns and perform aggregate functions.

**# SQL PIVOT TABLES EXAMPLE:**

USE Bank;

WITH cte_2 AS (
SELECT account_id, round(sum(amount),2) as amount, date_format(date, "%M") as month
from bank.trans
WHERE date_format(date, "%Y") = 1993 AND date_format(date, "%m") <= 3
group by 1,3
order by 1,3
)

SELECT account_id,
MIN(CASE WHEN month = 'January' then amount end) as January,
MIN(CASE WHEN month = 'February' then amount end) as February,
MIN(CASE WHEN month = 'March' then amount end) as March
FROM cte_2
GROUP by 1
ORDER BY 1