我要一些选定的列。我试图对fee
求和。但这会引发错误:
违反完整性约束:1052字段中的列“ service_fee” 列表不明确(SQL:从...中选择count(*)作为汇总.........
我已经尝试过以下方法。有人可以帮忙吗?预先感谢。
$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');
答案 0 :(得分:1)
您能将所有总和相加吗?
->selectRaw('sum(tt.service_fee) + sum(tt.order_service_fee) + sum(tt.order_service_fee_per) as fee')