求大神帮忙把原生的 sql 转换为 Laravel 格式,非常感谢🙏

select a.click_date,ifnull(b.income,0) as income
from (
    SELECT curdate() as click_date
    union all
    SELECT "2020-04-30" as click_date
    union all
    SELECT "2020-05-01" as click_date
    union all
    SELECT "2020-05-02" as click_date
        union all
    SELECT "2020-05-03" as click_date
        union all
    SELECT "2020-05-04" as click_date
        union all
    SELECT "2020-05-05" as click_date
        union all
    SELECT "2020-05-06" as click_date
        union all
    SELECT "2020-05-08" as click_date
) a left join (
  select DATE_FORMAT(ub_orders.pay_time,"%Y-%m-%d") days, 
    sum((IFNULL(ub_order_infos.distributors_income,0))-(IFNULL(ub_order_infos.merchant_income,0))) as income
  from ub_orders left join ub_order_infos on ub_orders.id=ub_order_infos.order_id
  group by days
) b on a.click_date = b.days
order by a.click_date asc;
chapin
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

laravel要活学活用,不要生搬硬套Eloquent ORM,这么复杂的语句就不要想着用ORM了:satisfied:

3年前 评论
讨论数量: 8
╰ゝSakura

干嘛不用php处理?

3年前 评论
chapin (楼主) 3年前
自由与温暖是遥不可及的梦想

你应该写 a 表 b表 都有啥字段 关联关系是啥 查询条件是啥 这样 我能看的更加明白。 要实现什么

3年前 评论

不懂 不会 不帮
素质三连
再见 :see_no_evil:

3年前 评论

难度太大了点,关注中。

3年前 评论

DB::select();了解下? :grin:

3年前 评论

laravel要活学活用,不要生搬硬套Eloquent ORM,这么复杂的语句就不要想着用ORM了:satisfied:

3年前 评论

复杂的就别折腾自己和别人了,写原生sql没毛病

3年前 评论

这种关系不适合 ORM

3年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!