here first query
select distinct u.email, lastorder, datediff(curdate(),lastorder), case when datediff(curdate(),lastorder)<=29 "<=29" when datediff(curdate(),lastorder)<=43 "<=43" when datediff(curdate(),lastorder)<=60 "<=60" when datediff(curdate(),lastorder)<=92 "<=92" when datediff(curdate(),lastorder)<=100 "<=100" else ">100" end dayssincelastorder pedidos_onlines po left join establecimientos e on `po`.`establecimiento_id`= e.id left join usuarios u on po.usuario_id=u.id left join ciudades c on c.id=e.ciudad_id left join (select usuarios.email, max(fecha) lastorder pedidos_onlines left join usuarios on pedidos_onlines.usuario_id=usuarios.id group usuarios.email) lastorder on u.email=lastorder.email (e.nombre or e.ciudad_id not null)and u.email not null order datediff(curdate(),lastorder) asc here second
select usuarios.email, avg(pedidos_onlines.total), case when p.nombre '%colombia%' , avg(pedidos_onlines.total) <34873 'a' when p.nombre '%colombia%' , avg(pedidos_onlines.total) >= 52309 'b' when p.nombre '%colombia%' 'c' when p.nombre '%peru%' , avg(pedidos_onlines.total) <41 'a' when p.nombre '%peru%' , avg(pedidos_onlines.total) >= 62 'b' when p.nombre '%peru%' 'c' when p.nombre '%ecuador%' , avg(pedidos_onlines.total) <13 'a' when p.nombre '%ecuador%' , avg(pedidos_onlines.total) >= 19 'b' when p.nombre '%ecuador%' 'c' else "" end segment, p.nombre country pedidos_onlines left join usuarios on usuarios.id=pedidos_onlines.usuario_id left join ciudades c on c.id=pedidos_onlines.ciudad_id left join paises p on p.id=c.pais_id usuarios.email not null group usuarios.email, p.nombre not quite sure how put them together, appreciated
use union - see https://dev.mysql.com/doc/refman/5.0/en/union.html
make sure both selects have same number of columns.
Comments
Post a Comment