1. 程式人生 > >thinkphp下group by分組後獲取每組最新資料

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();


預設是獲取第一條資料 子查詢可以很好的解決這個問題