sql - Pivoting in MySQL table -


i have mysql table named switches follows:

switchname  switchcondition switchingtime  ----------- --------------- -------------  first       on              10:00       first       off             11:00 second      on              10:30       third       off             13:00       third       on              13:45   

how can display report html table in following format using above table pivoting switching time respect switch condition?

switchname   on     off  ----------- -----  ------- first       10:00   11:00                    second      10:30    -         third       13:45   13:00 

try this:

select s.switchname,         max(case when s.switchcondition = 'on' s.switchingtime else '-' end) switchon,         max(case when s.switchcondition = 'off' s.switchingtime else '-' end) switchoff switches s  group s.switchname; 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -