mysql - How can i show dynamic row data into dynamic column -


hi have 1 table have 2 colums want show column 2 data in different column nothing fix every thing dynamic column creation based on rows

table 1

id col1 col2 1   x   aa 2   x   bb 3   x   cc 4   y   ww 5   y   ee 6   z   hh 7   z   tt 8   z   uu 9   z   pp 10  z   oo 

i want table1 data in format

id val1 val2 val3 val4 val5 val6 1   x    aa   bb   cc   null null 2   y    ww   ee   null null null 3   z    hh   tt   uu   pp   oo 

can 1 please me out how can in mysql

this result:

| id | val1 | val2 | val3 |   val4 |   val5 |   val6 | |----|------|------|------|--------|--------|--------| |  1 |    x |   aa |   bb |     cc | (null) | (null) | |  4 |    y |   ww |   ee | (null) | (null) | (null) | |  6 |    z |   hh |   tt |     uu |     pp |     oo | 

from query:

select       min(id)                                id     , col1                                   val1     , max(case when colno = 1 col2 end) val2     , max(case when colno = 2 col2 end) val3     , max(case when colno = 3 col2 end) val4     , max(case when colno = 4 col2 end) val5     , max(case when colno = 5 col2 end) val6 (       select                @row_num :=if(@prev_value = t.col1, @row_num + 1,1) colno              , t.id              , t.col1              , t.col2              , @prev_value := t.col1 pv       table1 t       cross join(select @row_num := 1 x, @prev_value :='' y) vars       order t.col1, t.id asc       ) sq group       col1 order       col1 ; 

but should note sites such not places cough finished work nothing. supposed demonstrate have tried @ least. claiming urgency isn't helpful, provide answers have work , entirely voluntary.

please prepare next question evidence of research , attempted query.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -