Can you help to modify the query or other query for getting the expected result

前端 未结 1 412
执笔经年
执笔经年 2021-01-19 10:24

I tried many way but didn\'t get expected result. How can I get expected result.

You can download the dbtable structure from here :-

SELECT 
    IF(         


        
相关标签:
1条回答
  • 2021-01-19 10:38

    According to your database schema, if you just want your expected result, please try following 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 
    

    SQLFiddle DEMO HERE.

    0 讨论(0)
提交回复
热议问题