thinkphp下group by分组后获取每组最新数据



$lock = M('locked_record');

 

$type = 1;

 

$subQuery = $lock->table('sys_locked_record')

->where(array('type'=>$type))

->order('addtime desc')

->buildSql();

$res = $lock->table($subQuery.'a')->group('uid')->select();



默认是获取第一条数据 子查询可以很好的解决这个问题