sql >> Base de Datos >  >> RDS >> Mysql

¿Puede ayudar a modificar la consulta u otra consulta para obtener el resultado esperado?

De acuerdo con el esquema de su base de datos, si solo desea el resultado esperado, intente seguir sql;)

select 
    case source_id when 1 then 'online' when 2 then 'visit' when 3 then 'phone' end as `Type`,
    sum(if(month(date_created) = 5, total_price, 0)) as `May`,
    sum(if(month(date_created) = 6, total_price, 0)) as `June`
from `orders`
where date_created between (curdate() - interval 1 month) and curdate()
group by source_id 

DEMOSTRACIÓN DE SQLFiddle AQUÍ .