码迷,mamicode.com
首页 > 数据库 > 详细

Yii 实现数据库SUM操作

时间:2014-11-26 11:02:18      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   ar   color   sp   数据   on   

方法一:这种方法有个坑儿,就是as 后面的别名,必须是属性范围内的名字。

$criteria = new CDbCriteria();  
$criteria->select = ‘sum(amount) total‘;  
$criteria->order = ‘wom_id desc’;  
$criteria->addCondition(“wom_id=4");//也可以$criteria->condition = "$wom_id=4";  
$aResult = Member::model()->findAll($criteria);

 

方法二:

//获取账户已到帐总额
    public static function GetAmountAlreadyArrive($int_wom_id){
        $connection = Yii::app()->weimob_payment;
        $str_sql  = "select sum(`ww_amount`) as `total_balance` from `t_wm_weimobpay_withdrawal_new`";
        $str_sql .= " where wom_id={$int_wom_id} and ww_pay_status=1 and ww_check_status=1";
        $command = $connection->createCommand($str_sql);
        return $command->queryAll();
    }
    
    //获取账户提现总额
    public static function getCashamount($int_wom_id){
        $connection = Yii::app()->weimob_payment;
        $str_sql  = "select sum(`ww_amount`) as `total_balance` from `t_wm_weimobpay_withdrawal_new`";
        $str_sql .= " where wom_id={$int_wom_id} and ww_check_status!=2";
        $command = $connection->createCommand($str_sql);
        return $command->queryAll();
    }

 

Yii 实现数据库SUM操作

标签:des   style   blog   io   ar   color   sp   数据   on   

原文地址:http://www.cnblogs.com/sungx/p/4122536.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!