一些SQL

一、统计出某个表中得到积分大于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

相关文章
相关标签/搜索