Mysql select data in same row -
i'm confused query. data 1 context in 1 row. don't know how that. here's tables's sample.
data (table) io(table) iddata idio readval no idio idcontext 1 io1 12 1 io1 c1 2 io2 12.5 2 io2 c1 3 io3 11 3 io3 c1 4 io4 12.2 1 io4 c2 5 io5 10 2 io5 c2 6 io6 10.9 3 io6 c2
i result
idcontext io-1 io-2 io-3 c1 12 12.5 11 c2 12.2 10 10.9
i've tried in loop print in table , works, in query faster.
actually, query looks :
select idcontext, idinput, readval data left join io on io.idio = data.idio order idcontext, no
is possible result in 1 single query?
you can conditional aggregation:
select idcontext, max(case when no = 1 data.readval end) io1, max(case when no = 2 data.readval end) io2, max(case when no = 3 data.readval end) io3 data left join io on io.idio = data.idio group idcontext order idcontext;
Comments
Post a Comment