mysql - How can I aggregate data from multiple rows into a single one spread across multiple columns? -


i have table in database , want aggregate data multiple rows single 1 spread across multiple columns:

 id     pid        date              time 1      12         10/04/2014        7:00 2      12         10/04/2014        10:00 3      12         10/04/2014        15:00 4      13         10/04/2014        7:00 5      13         10/04/2014        15:00 6      12         11/04/2014        7:20 7      12         11/04/2014        15:10 8      13         11/04/2014        7:10 9      13         11/04/2014        7:50 10     13         11/04/2014        15:00 11     13         11/04/2014        15:50 

pid employee id, specific it's attendance system. need extract format , insert form in table:

 id      pid      date               time1          time2         time3       time4 1       12       10/04/2014         7:00           10:00         15:00 2       13       10/04/2014         7:00           15:00 3       12       11/04/2014         7:20           15:10 4       13       11/04/2014         7:10           7:50          15:00       15:50    

while concerns stated in comments valid, i'll assume have reason specific requirement.

this solution work mssql:

sql fiddle, mssql 2008+

this solution work mysql:

sql fiddle, mysql 5.5.32


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 -