當對它們形成集合被推到laravel數據表生成器中的查詢:一般錯誤:2031聯合兩個查詢(laravel數據表)
foreach (Session::get('trienios') as $trienio) {
$oeTrienios = $oeTrienios->where('data_trienio', $trienio->trienio)->whereHas('curso', function ($query) use ($trienio) {
$query->where('curso', $trienio->curso);
});
}
$union = Trienio::with('curso')->whereHas('curso', function ($query) use ($coordinatedCourse) {
$query->where('curso', $coordinatedCourse);
})->union($oeTrienios);
$trienios = \DB::table(\DB::raw("({$union->toSql()}) as x"))->select(['data_trienio']);
有官方laravel-的DataTable網站教程該「解釋」如何與聯合國查詢的工作,但它是非常模糊的,不能真實地說明什麼,而且,當我試圖增加他們對本教程代碼:
$trienios = \DB::table(\DB::raw("({$union->toSql()}) as x"))
它給我出現以下錯誤:
SQLSTATE[HY000]: General error: 2031 (SQL: select count(*) as aggregate from (select `data_trienio` from ((select * from `trienios` where exists (select * from `cursos` where `trienios`.`curso_id` = `cursos`.`id` and `curso` = ?)) union (select * from `trienios` where `data_trienio` = ? and exists (select * from `cursos` where `trienios`.`curso_id` = `cursos`.`id` and `curso` = ?) and `data_trienio` = ? and exists (select * from `cursos` where `trienios`.`curso_id` = `cursos`.`id` and `curso` = ?))) as x) count_row_table)
但是,如果我將參數->get()
附加到->union($oeTrienios)
,它將工作得很好,但是,該集合在數據表上無法收錄。
我該如何解決這個問題?任何幫助將是非常受歡迎的。
P.S - 鏈接到演示:https://datatables.yajrabox.com/fluent/union
您可以提一下鏈接到聯合查詢教程嗎? –
添加到帖子中。 –