Trip::select('trips.id','trips.date_trip',
DB::raw('(select count(region_id) as count from trip_regions where trip_id=trips.id) as count')
)->where('count',10)->get();ERRor
"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'count' in
'where clause' (SQL: select `trips`.`id`, `trips`.`date_trip`, (select
count(region_id) as sum from trip_regions where trip_id=trips.id) as
count from `trips` where `count` = 10)我有查询行想要DB::raw。你能帮我吗?非常感谢
发布于 2018-05-14 14:57:51
用having子句试试这个
Trip::select('trips.id','trips.date_trip',
DB::raw('(select count(region_id) as count from trip_regions where trip_id=trips.id) as count')
)->having('count', '=',10)->get();不能对自定义别名应用where子句,where只适用于表中存在的列。要筛选出表达式/聚合结果集的结果,需要having子句
https://stackoverflow.com/questions/50333364
复制相似问题