记录下我的一条很长的sql

这篇博客记录了作者长时间专注于编写一条复杂SQL的过程,展现了程序员日常的沉浸式工作状态。
摘要由CSDN通过智能技术生成

一杯水,一支烟,一行代码写一天


public function viewForStatistic()
    {
   
        $bargainGoodsProductSql = (new ShopToolBargainGoodsProductMO())->alias('bgp')
            ->join((new ShopGoodsProductMO())->getTableName() . ' gp', 'bgp.product_no = gp.product_no', 'left')
            ->where('bgp.delete_time', '=', 0)
            ->group('gp.goods_no')
            ->field(Db::raw('gp.goods_no, bgp.product_no, min(bgp.price) as price, gp.product_price'))
            ->buildSql();

        $goodsSql = (new ShopGoodsMO())->alias(' sg')
            ->where('delete_time', '=', 0)
            ->join($bargainGoodsProductSql . ' sgp', 'sg.goods_no = sgp.goods_no')
            ->field('sg.goods_no,sg.goods_title,sg.goods_cover,sg.goods_price,sgp.price,sgp.product_price')
            ->buildSql();

        $countSql = (new ShopToolBargainApplyMO())
            ->group('bargain_no')
            ->field(Db::raw('bargain_no, count(*) as apply_count,count( if ( exchange_status =' . ShopToolBargainApplyConstant::EXCHANGE_STATUS_HAS_EXCHANGE . ',id,null)) as receive_count,count( if ( status =' . ShopToolBargainApplyConstant::STATUS_SUCCESS . ',id,null)) as success_count,count(distinct student_no) as apply_user_count, count( distinct if ( status =' . ShopToolBargainApplyConstant::</
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值