0

I have this mysql query:

SELECT stats.date,
           SUM (stats.MOROCCO_EUR_SPA),
           SUM (stats.TUNISIA_EUR_SPA),
           SUM (stats.TURKEY_EUR_SPA),
           SUM (stats.GREECE_EUR_SPA)
    FROM stats
    WHERE DATE(date) BETWEEN '2010-08-01' AND '2011-07-31'

And it gives me, 5 columns.

date        MOROCCO_EUR_SPA TUNISIA_EUR_SPA TURKEY_EUR_SPA GREECE_EUR_SPA
01/08/2010       150            265              193          357

I want to transpose the columns into rows, like this:

                   date        

MOROCCO_EUR_SPA     150
TUNISIA_EUR_SPA     265
TURKEY_EUR_SPA      193
GREECE_EUR_SPA      357

I've tried a lot things, but I didn't get close to the solution.

Thanks in advance.

kurtinho
  • 13
  • 2
  • Possible duplicate of [MySQL - turn table into different table](https://stackoverflow.com/questions/15184381/mysql-turn-table-into-different-table) – lc. Nov 07 '17 at 10:29
  • 1
    _"I've tried a lot things"_ You should post what those are, so people don't tell you things you've already discounted. _"but I didn't get close to the solution."_ What **did** you get? – underscore_d Nov 07 '17 at 10:30
  • There are many, many, many questions like this. That's why you should explain whether you searched, and if so, why the questions you found didn't help. (Or if not, why you didn't search.) e.g. Possible duplicate of [Mysql Convert Column to row (Pivot table )](https://stackoverflow.com/questions/13944417/mysql-convert-column-to-row-pivot-table) – underscore_d Nov 07 '17 at 10:31
  • 1
    As usual, the answer is to normalize your schema. – symcbean Nov 07 '17 at 10:31
  • As symcbean suggests, this problem is highly symptomatic of poor design. Fix your schema design, and the problem will magically disappear. – Strawberry Nov 07 '17 at 10:42

0 Answers0