mysql - How to transpose the table in SQL -
table abc:
cookie_id key time 123 search 5/6/15 123 search 5/7/15 123 homepage 5/6/15 123 book 5/12/15 234 homepage 5/7/15 234 search 5/8/15
expected result below :
cookie_id homepage search book 123 5/6/15 123 5/6/15 123 5/7/15 123 5/12/15 234 5/7/15 234 5/8/15
how make expected result table tableabc????
use case
statement desired result.
select cookie_id, case when key = 'search' time else null end search, -- can replace null empty string case when key = 'homepage' time else null end homepage, case when key = 'book' time else null end book yourtable
Comments
Post a Comment