一、統計出某個表中得到積分大於20000分的用戶ui
$having='gp_score>=1000 and gp_score<5000';
this
$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();it
二、根據用戶uid統計抽獎總數select
方法1:
方法
$list=$this->GuagualePrizesModel->field("count(*) as gp_count,gp_uid")->group("gp_uid")->order('gp_count desc')->limit($first,$pagesize)->select();im
方法2:
統計
SELECT count(DISTINCT gp_uid) as total FROM `js_guaguale_prizes` order by total desc
vi