求大神帮忙把原生的 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
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
最佳答案

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年前 评论

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