Yii中 - 使用活动记录获取最小值,最大值列 [英] Yii - Get min, max of a column using active record
本文介绍了Yii中 - 使用活动记录获取最小值,最大值列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的活动记录。让我们致电型号产品。我怎样才能得到选择tbl_product分钟(价格),其中,名称,比如'%发胶%使用活动记录?
I am using active record. Lets call the model Product. How can i get "select min(price) from tbl_product where name like '%hair spray%'" using active record?
推荐答案
您可以使用这样的:
$criteria = new CDbCriteria;
$criteria->select='MIN(price) as minprice';
$criteria->condition='name LIKE :searchTxt';
$criteria->params=array(':searchTxt'=>'%hair spray%');
$product = Product::model()->find($criteria);
您将只需要声明:
公共$ minprice;在模型类
。 (使用上面的例子。)
You would just need to declare:
public $minprice;
in your model class. (Using the above example.)
这篇关于Yii中 - 使用活动记录获取最小值,最大值列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文