1、统计出某个表中获得积分大于20000分的用户
$having='gp_score>=1000 and gp_score<5000';
$list=$this->GuagualePrizesModel->field("sum(gp_amount) as gp_score,gp_uid")->group("gp_uid")->having($having)->where(array('gp_prizes_type'=>4))->order('gp_score desc')->select();
2、根据用户uid统计抽奖总数
方法1:
$list=$this->GuagualePrizesModel->field("count(*) as gp_count,gp_uid")->group("gp_uid")->order('gp_count desc')->limit($first,$pagesize)->select();
方法2:
SELECT count(DISTINCT gp_uid) as total FROM `js_guaguale_prizes` order by total desc