Monday 15 August 2011

join - Add column average in output MySQL -



join - Add column average in output MySQL -

i want add together column of avg in existing output. first calculate usage of electricity , gas inner join. want add together avg of "day hour" output.

table columns

id, datum, tijd, consumed_rate1, consumed_rate2, gas

when want output of lastly 24 records usage of consumed_rate1, consumed_rate2 , gas, utilize query:

select a.datum datum, a.tijd tijd, a.daguur daguur, a.aantal aantal, a.consumed_rate1 + a.consumed_rate2 elektra, (a.consumed_rate1 + a.consumed_rate2 - b.consumed_rate1 - b.consumed_rate2) 'elektra verbruikt', a.gas gas, (a.gas - b.gas) 'gas verbruikt' smartmeter inner bring together smartmeter b on b.id = (a.id-1) order a.id desc limit 24

now want add together column avg of usage consumed_rate1 + consumed_rate2 , gas. think must work left joins, don’t know how. there body help me that?

try this:

select avg(elektra), avg(gas) from( select a.datum datum, a.tijd tijd, a.daguur daguur, a.aantal aantal, a.consumed_rate1 + a.consumed_rate2 elektra, (a.consumed_rate1 + a.consumed_rate2 - b.consumed_rate1 - b.consumed_rate2) 'elektra verbruikt', a.gas gas, (a.gas - b.gas) 'gas verbruikt', smartmeter inner bring together smartmeter b on b.id = (a.id-1) order a.id desc limit 24 )

mysql join average

No comments:

Post a Comment