so in MySQL I have a table like:
date | account | amount |
---|---|---|
2021-01 | 1 | 3000 |
2021-01 | 2 | 2100 |
2021-01 | 3 | 1800 |
2021-02 | 1 | 3500 |
2021-02 | 2 | 1500 |
2021-02 | 3 | 2500 |
since it has 3 different accounts on 2 different date, I want to group it by date and account then count average so the table would be like:
date | account1 | account2 | account3 | average_amount |
---|---|---|---|---|
2021-01 | 3000 | 2100 | 1800 | 2300 |
2021-02 | 3500 | 1500 | 2200 | 2400 |
what do you think the best query to achieve the result to convert account rows into columns in MySQL?