A、B 两个表。A 为主表。B 为附表。A 表 left join B(B 表按某一字段取最大分组)如何实现?
select count(*) as aggregate from `new_houses`
left join
(select max(open_date) as open_date, price, new_house_id from quotas group by new_house_id) as a
on `new_houses`.`id` = `a`.`new_house_id`
where `is_lock` = 'F' and `city_id` = 1`
这个在sql里执行没问题,但是实际在代码里执行报错有人知道吗?
报错如下:
SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'house.quotas.price' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select count(*) as aggregate from new_houses
left join (select max(open_date) as open_date, price, new_house_id from quotas group by new_house_id) as a on new_houses
.id
= a
.new_house_id
where is_lock
= F and city_id
= 2)
推荐文章: