mysql as a group_mysql – A. *不在GROUP BY中,并且在laravel查询...

要解决此问题,您需要在select list和group by子句中指定必需的列

$search_alls=DB::table('a16s as A')

->select('A.id','A.name')

->addSelect(DB::raw('SUM(CASE WHEN B.approve = 1 ELSE 0 END) as Yshow'))

->leftjoin('a16s_likes as B', function($join) {

$join->on('A.id', '=', 'B.p_id');

})

->groupBy('A.id')

->groupBy('A.name');

->get();

As per newer release mysql 5.7 does not permit queries for which the select list, HAVING condition, or ORDER BY list refer to nonaggregated columns that are not named in the GROUP BY clause

按照文档

MySQL 5.7.5 and up implements detection of functional dependence. If the 07001 SQL mode is enabled (which it is by default), MySQL rejects queries for which the select list, HAVING condition, or ORDER BY list refer to nonaggregated columns that are neither named in the GROUP BY clause nor are functionally dependent on them. (Before 5.7.5, MySQL does not detect functional dependency and 07001 is not enabled by default

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值