Laravel雄辩COUNT(*)没有结果的GroupBy()

问题描述 投票:0回答:1

我有laravel查询

$types=Types::selectRaw('COUNT(property_types.id) as total, property_types.types, property_types.id')

               ->join('properties', 'property_types.id', '=', 
                      'properties.property_type')
               ->where('property_purpose', '"Sale"')
               ->groupBy('property_types.id','property_types.id','property_types.types')
               ->get();

和我没有任何结果

Collection {#383 ▼

#it​​ems:[]

我改变 - >获得()通过 - > toSql();我有laravel查询

select COUNT(property_types.id) as total, property_types.types, property_types.id 
from `property_types` 
inner join `properties` on `property_types`.`id` = `properties`.`property_type`
where `property_purpose` = ? 
group by `property_types`.`id`, `property_types`.`id`, `property_types`.`types`

改变吗?通过变量“卖”拷贝并粘贴phpMyAdmin的,我得到了我想要的结果

enter image description here

我不知道错在Laravel雄辩什么!

php mysql laravel-5 eloquent
1个回答
0
投票

对于我这种工作

$类型=类型:: selectRaw( 'COUNT(property_types.id)为总,property_types.types,property_types.id')

           ->join('properties', 'property_types.id', '=', 
                  'properties.property_type')
           ->where('property_purpose', 'Sale')
           ->groupBy('property_types.id','property_types.id','property_types.types')
           ->get();
© www.soinside.com 2019 - 2024. All rights reserved.