1

I have the following data.

enter image description here

I want to get a pivot result based on merchants as rows and Month, Year, Type as columns and Amount as the agg value.

enter image description here

I know the use of case clause in Mysql but I wish to automate it for the upcoming data and don't want to hard code month, Year and type since I have thousands of "Types" in the real data.

Thanks in advance.

  • MySQL cannot produce "joined cells" (`1,2021`, `2,2021`, etc. on your screenshot). Without this you may use stored proc with dynamic SQL. – Akina Apr 21 '21 at 11:27
  • I am fine with not having "joined cells" but, is there a way to get the rest of the data? – Nikhil Kumar Singh Apr 21 '21 at 11:53
  • You may have not `T_1` but `1, 2021, T_1` headers. If it is safe for you then see [this](https://stackoverflow.com/a/66136355/10138734) – Akina Apr 21 '21 at 11:55

0 Answers0