sql - MySQL dynamic transpose/pivot of a table -


i've been trying pivot sample table:

type       | count ___________________ 'chains'   | '38' 'indep'    | '64' 'super'    | '25' 

yup, it's simple. i've been reading tutorials, stackoverflow answers , i've been looking tutorial transposing table. can't understand , haven't been able accomplish following result:

chains | indep | super _______________________ 38     | 64    | 25 

i know there other questions similar one, can't point reading. examples use multiple tables explain or have code no explanmation, , can't undestrand what's needed this. can please explain me in detail how can accomplish pivoted table??

thanks lot!!


edit 1:

with tutorials i've read, i've manage following:

chains | indep | super _______________________ 38     | null  | null null   | 64    | null null   | null  | 25 

i'd data in single row without null. know there tutorials , answers don't understand clearly. i'd explanation of whats logic pivot table.

@bluefeet told me needed aggregate function. sum() got single row


edit 2:

this query i'm using works (thansk @bluefeet) it's not dynamic: can't know sure columns i'll need.

select   sum(case when sq.type = 'chains' sq.count end) chains,   sum(case when sq.type = 'indep' sq.count end) indepe,   sum(case when sq.type = 'super' sq.count end) super subquery1 sq 

how can similar result dynamic query? thanks


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -