代码之家  ›  专栏  ›  技术社区  ›  Chonchol Mahmud

如何对所有聚合值SQL-Laravel求和?

  •  0
  • Chonchol Mahmud  · 技术社区  · 6 年前

    fee . 但它抛出了一个错误:

    列表不明确(SQL:select count(*)as aggregate from。。。。。。。。。。

    我已经试过了。有人能帮忙吗?提前谢谢。

    $events = Event::select($columns)->EventComplete()
                ->where('events.event_end_date', '<', $currentDate)
                ->where('events.have_balance', '>', 0)
                ->join('role_users_details as rud', 'events.promoter_id', '=', 'rud.id')
                ->join('transaction as tra', 'events.id', '=', 'tra.event_id', 'left outer')
                ->join(\DB::raw("(select tran.id as ttid, sum(tran.ticket_price) as total_amt, sum(tran.ticket_service_fee) as service_fee, tran.order_service_fee as order_service_fee,tran.order_service_fee_per as order_service_fee_per , count('ticket_order.*') as total_tickets
        from `transaction` as `tran`
        right join `ticket_order` on `tran`.`id` = `ticket_order`.`transaction_id`
        where `ticket_order`.`status` = 1 group by `ttid`) as tt"), 'tt.ttid', '=', 'tra.id', 'left outer  ')
                ->selectRaw('CONCAT_WS(" ", rud.first_name, rud.middle_name, rud.last_name) as promoter')
                ->selectRaw('sum(tt.total_amt) as tickets')
                ->selectRaw('sum(tt.service_fee) as service_fee')
                ->selectRaw('sum(tt.order_service_fee) as order_fee')
                ->selectRaw('sum(tt.order_service_fee_per) as order_fee_per')
                ->selectRaw('sum(tt.total_tickets) as total_tickets')
                ->selectRaw('(service_fee + order_fee + order_fee_per) as fee')
                ->selectRaw('FROM_UNIXTIME(events.event_end_date, "%Y/%m/%d %h:%i:%s") as ending_date')
                ->groupBy('events.id');
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Matt Jameson    6 年前

    你能把所有的总数加起来吗?

    ->selectRaw('sum(tt.service_fee) + sum(tt.order_service_fee) + sum(tt.order_service_fee_per) as fee')