求大神帮忙把原生的 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
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

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

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

干嘛不用 php 处理?

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

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

4年前 评论

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

4年前 评论

难度太大了点,关注中。

4年前 评论

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

4年前 评论

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

4年前 评论

这种关系不适合 ORM

4年前 评论