$c = table1::leftJoin('table2', function($join) {
$join->on('table1.location', '=', 'table2.location');});
$c->select(DB::Raw("
table1.*,
SUM(table2.population) as total_population,
SUM(table2.population"));
if($data->max_age != NULL){
DB::statement("
where `$data->min_age`>= demographics.age
where table2.age <= `$data->max_age`
");
}
if($data->max_income != NULL){
DB::statement("
where `$data->min_income`>= table2.income
where table2.income <= `$data->max_income`
");
}
DB::statement("
)
");
*/
return $c->get();
table1:location,etc.
table2:location,income,age,population
output:location = USA
total_population = 55000
selected_population = 1000
我想知道如何正确实施它。我在运行中遇到了一些不同的错误,如果有人能帮助我,我将不胜感激。