group concat - MySQL group_concat query help needed -


i have mysql database.i have table contains list of procedures , estimated time suggested different developers.

as follows:

proc_name   user_id    est_time ------------------------------- 'a'           1           20 'a'           3           15 'b'           2           16 'b'           4           18 'c'           1           20 

now need output this

a|1_20|2_0 |3_15|4_0 b|1_20|2_16|3_0 |4_18 c|1_20|2_0 |3_0 |4_0 

if user not posting hours proc_name, '0' printed.

any appreciated.

this isn't "group_concat". example of pivoting.

select proc_name,        concat('1_', max(case when user_id = 1 est_time else 0 end)),        concat('2_', max(case when user_id = 2 est_time else 0 end)),        concat('3_', max(case when user_id = 3 est_time else 0 end)),        concat('4_', max(case when user_id = 4 est_time else 0 end)) t group proc_name 

i find strange, though, putting user 1's in first column and putting the "1" in column value.

actually, if want data single string, can concatenate above results rather putting them in separate columns:

select concat_ws('|', proc_name,                  concat('1_', max(case when user_id = 1 est_time else 0 end)),                  concat('2_', max(case when user_id = 2 est_time else 0 end)),                  concat('3_', max(case when user_id = 3 est_time else 0 end)),                  concat('4_', max(case when user_id = 4 est_time else 0 end))                 ) t group proc_name 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -