$records = DB::table('history as a')
->join('reservation2 as b', function($join){
$join->on('a.id', '=', 'b.id')
->on('a.sid', '=', 'b.sid');
})
->whereBetween('a.date', [$sDate, $eDate])
->select('a.*', DB::raw('SUM(a.perday) AS revenue'), 'b.name', 'b.checkin', 'b.checkout', 'b.status')
->groupBy('a.id')
->groupBy('a.sid')
->toSql();
给我以下查询:
select `a`.*, SUM(a.perday) AS revenue, `b`.`name`, `b`.`checkin`, `b`.`checkout`,
`b`.`status`
from `history` as `a`
inner join `reservation2` as `b` on `a`.`id` = `b`.`id` and `a`.`sid` = `b`.`sid`
where `a`.`date` between ? and ? group by `a`.`id`, `a`.`sid`
如果从mysql命令提示符传递查询,则显示许多记录但如果我用->toSql()
替换->get()
,则它不会给我任何记录。
有什么问题?