select - MySQL table to column list query -


i trying workout how query table have , produce specific output format in select statement. source table data follows

+-----------+------------------------+ | prefix_id | description  |  | b  | +-----------+------------------------+ |     55207 | test 1       | 1  | 0  | |     55363 | test 2       | 1  | 0  | |     55378 | test 3       | 0  | 1  | |     55379 | test 4       | 1  | 1  | +-----------+------------------------+ 

the output desire above data follows

+-----------+------------+ |         | b          | +-----------+------------| | test 1    | test 3     | | test 2    | test 4     | | test 4    | null       | +-----------+------------+ 

as can see test 4 description appears twice true column , b order unimportant. null characters should appear @ end of column or b. ids not important long each entry appears once under corresponding columns.

maybe temporary table can't figure out how. separate queries column or b easy merging them output problem.

imagine output being see in excel, want data @ top of column filled out blanks @ bottom

your appreciated.

note. looking achieve in sql query. query output gets rendered using called mydbr analytics reporting tool.

you can in sql. trying align 2 lists -- fortunately, don't care order (because have no column specify ordering).

the following breaks data in 2 pieces, 1 "a" column , 1 "b" column. uses mysql trick calculate sequential number (other databases use row_number() this).

here query:

select max(a), max(b) ((select @rn1 := @rn1 + 1 rn, description a, null b        t cross join (select @rn1 := 0) const        = 1       ) union       (select @rn2 := @rn2 + 1 rn, null a, description b        t cross join (select @rn2 := 0) const        b = 1       )      ) t group rn 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -