1.问题产生
$teacherIds = \app\model\Follow::where('shop_id', '=', 18) ->field('MAX(id) as id') ->group('member_id') ->order('id', 'desc') ->column('id');
此处生成的sql如下,可以看到max(id)已经没了
SELECT `id` FROM `sat_follow` WHERE ( `shop_id` = 18 ) AND `sat_follow`.`delete_time` IS NULL GROUP BY `member_id` ORDER BY `id` DESC
2.问题解决
$teacherIds = \app\model\Follow::where('shop_id', '=', 18) ->group('member_id') ->order('id', 'desc') ->column('MAX(id) as id');
3.思路
1.把column换成select
$teacherIds = \app\model\Follow::where('shop_id', '=', 18) ->field('MAX(id) as id') ->group('member_id') ->order('id', 'desc') ->select();
生成的sql是
SELECT MAX(id) as id FROM `sat_follow` WHERE ( `shop_id` = 18 ) AND `sat_follow`.`delete_time` IS NULL GROUP BY `member_id` ORDER BY `id` DESC
2.可以看到是column影响的,大胆推测column有自己的限定字段逻辑
$teacherIds = \app\model\Follow::where('shop_id', '=', 18) ->group('member_id') ->order('id', 'desc') ->column('MAX(id) as id');
4.原因
//1.vendor\topthink\think-orm\src\db\BaseQuery
//2.connection–这个是数据库构造对象(第一行的result已经把column处理完了)
//3.interface是集成不是实际处理代码的
//4.实际处理的是继承interface的类
//5.用的是mysql所以vendor\topthink\think-orm\src\db\PDOConnection的column方法