How do I left join onto a mysql range case group by query? -


how left join average onto query?

select t.range, count(*) num    (select case        when price < 50000 '0 - 49k'        when price >= 50000 , price < 100000 '50 - 99k'        when price >= 100000 , price < 200000 '100 - 199k'        ...        range,        price        table) t group range 

i've tried

select t.range, count(*) num, avg(b.val)    (select case        when price < 50000 '0 - 49k'        when price >= 50000 , price < 100000 '50 - 99k'        when price >= 100000 , price < 200000 '100 - 199k'        ...        range,        price        table) t     left join table2 b on b.id = t.id group range 

and various other feeble attempts no avail.

hard without knowing more "table2" , how relates "table", first thought join inside subquery instead of outside of it:

select t.range, count(*) num, avg(t.val)    (select case        when price < 50000 '0 - 49k'        when price >= 50000 , price < 100000 '50 - 99k'        when price >= 100000 , price < 200000 '100 - 199k'        ...        range,        t1.price,        b.val        table t1        left join table2 b on b.id = t1.id ) t group range 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -