I have a table like this:

enter image description here

And I want to get something like:

fecha       siguiendo    seguidores
2016-01-02    430           1430
2016-01-03    450            NULL
2016-01-04    NULL           5000

I have two types of data seguidores and siguiendo. I want a column for each of them.

I have tried to emulate a FULL JOIN on the same table but I didn't get the expected result. Any ideas?

  • table have primary key?
    – a_vlad
    Jan 2 '16 at 15:04
  • @a_vlad No. UNIQUE (user_id, dato, fecha) Jan 2 '16 at 15:21

This is called a pivot

SELECT fetcha,
SUM(CASE WHEN Dato='siguiendo' THEN valor END) as siguiendo,
SUM(CASE WHEN Dato='seguidores' THEN valor END) as seguidores
GROUP BY fetcha

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.