Запрос ниже выполняется в MySQL должным образом, однако тот же запрос не выполняется в Laravel.
select
SUM(g.TOTAL_WIN) AS TOTAL_WIN,
SUM(g.TOTAL_REVENUE) AS TOTAL_REVENUE,
SUM(g.REAL_REVENUE) AS TOTAL_REAL_RAKE,
SUM(g.BONUS_REVENUE) AS TOTAL_BONUS_RAKE,
SUM(g.SERVICE_TAX) as TOTAL_SERVICE_TAX
from
`ofc_game_history` as `g`
left join
`tournament_tables` as `tt`
on `tt`.`TOURNAMENT_TABLE_ID` = `g`.`TOURNAMENT_TABLE_ID`
left join
`tournament` as `t`
on `t`.`TOURNAMENT_ID` = `tt`.`TOURNAMENT_ID`
order by
`g`.`GAME_HISTORY_ID` desc
Я пробовал разные методы, показанные ниже.
#1
DB::select($query->selectRaw("SUM(g.TOTAL_WIN) AS TOTAL_WIN,
SUM(g.TOTAL_REVENUE) AS TOTAL_REVENUE,
SUM(g.REAL_REVENUE) AS TOTAL_REAL_RAKE,
SUM(g.BONUS_REVENUE) AS TOTAL_BONUS_RAKE,
SUM(g.SERVICE_TAX) as TOTAL_SERVICE_TAX")->toSql());
# 2
$query = OfcGameHistory::query();
$query->from(app(OfcGameHistory::class)->getTable()." as g");
// $query->select("g.GAME_HISTORY_ID","g.MINIGAMES_TYPE_ID","g.TOURNAMENT_TABLE_ID","g.PLAY_GROUP_ID","g.TOTAL_PLAYERS","g.TOTAL_WIN","g.TOTAL_REVENUE","g.APP_RAKE_PERCENTAGE","g.STARTED","g.ENDED","tt.TOURNAMENT_NAME","g.REAL_REVENUE","g.BONUS_REVENUE","g.SERVICE_TAX");
$query->selectRaw("SUM(g.TOTAL_WIN) AS TOTAL_WIN,SUM(g.TOTAL_REVENUE) AS TOTAL_REVENUE,SUM(g.REAL_REVENUE) AS TOTAL_REAL_RAKE,SUM(g.BONUS_REVENUE) AS TOTAL_BONUS_RAKE,SUM(g.SERVICE_TAX) as TOTAL_SERVICE_TAX");
$query->leftJoin('tournament_tables as tt', 'tt.TOURNAMENT_TABLE_ID', '=', 'g.TOURNAMENT_TABLE_ID');
$query->leftJoin('tournament as t', 't.TOURNAMENT_ID', '=', 'tt.TOURNAMENT_ID');
# 3
$query->select("SUM(g.TOTAL_WIN) AS TOTAL_WIN", "SUM(g.TOTAL_REVENUE) AS TOTAL_REVENUE",
"SUM(g.REAL_REVENUE) AS TOTAL_REAL_RAKE", "SUM(g.BONUS_REVENUE) AS TOTAL_BONUS_RAKE",
"SUM(g.SERVICE_TAX) as TOTAL_SERVICE_TAX");
# 4
$query->addSelect(DB::raw('SUM(g.TOTAL_WIN) as TOTAL_WIN'));
Я хочу, чтобы отдельные столбцы суммировались;Я не хочу группироватьЭтот же запрос выполняется правильно, но не в Laravel. Пожалуйста, кто-нибудь может подсказать, как мне это сделать?