我的Laravel查询不能正常工作。但是MySQL查询工作正常
Laravel查询:
$data = DB::table(DB::raw('select (sum(case when type="credit" then amount else -amount end)) - (select sum(amount) from total) from report'))
请参考sqlfiidle:http://sqlfiddle.com/#!9/2d0343/9中的mysql查询。
发布于 2017-10-24 13:29:34
与其重写MySQL查询,不如简化它,使它更有说服力。
假设$data是总体平衡,您的报表模型名为Report,那么下面的代码应该可以实现您想要的结果:
$data = Report::where('type', 'credit')->sum('amount') - Report::where('type', 'debit')->sum('amount');这将给你所有贷方的总和,减去你所有借方的总和。
https://stackoverflow.com/questions/46901836
复制相似问题