TP5.1统计某数据再领一张表出现的次数并且分组后查询最新的一条记录
用户表,用户登录信息表
public static function getList($type){ if ($type=='user'){ $map[] = ['u.type','=','1']; }elseif ($type=='admin'){ $map[] = ['u.type','=','2']; } $subsql = model('LoginInfo') -> order('time_nux','desc') -> buildSql(); $join = [ [[$subsql=> 'l'],'u.user=l.admin'] ]; return self::alias('u')->field('u.id,user,count(l.id) as frequency,u.time as new_time,max(time_nux) as time,country,ip,u.password') ->leftJoin($join) -> where($map) -> group('u.user') -> select(); }