我正在尝试使用统计查询来关联Yii中的3个表。我需要显示每个请求的最低速率,由登录用户发布的条件,其中“通信”=海和“国家”=中国,其中通信和国家是3个不同的表的属性。我如何实现这一点?在统计查询的情况下,有没有添加AND/Or的方法?我的代码如下所示。
return array(
'serviceproposals' => array(self::HAS_MANY, 'Serviceproposal', 'ServiceRequestID'),
'user' => array(self::BELONGS_TO, 'Buyer', 'user_id'),
'postCount'=>array(self::STAT, 'serviceproposal', 'ServiceRequestID'),
'maxvalue'=>array(self::STAT, 'serviceproposal', 'ServiceRequestID','select'=>'MAX(proposal_amount)'),
'minvalue'=>array(self::STAT, 'serviceproposal', 'ServiceRequestID','select'=>'MIN(proposal_amount)', 'condition' => 'Communications ="hai"'),
);数据库:
User[user_id,name,password,Country],
Provider[user_id,providercompany,providerdetails],
Buyer[user_id,contactinfo],
ServiceRequest[ServiceRequestID,Buyer.user_id,details,date],
ServiceProposal[ServiceProposalId,ServiceRequestID,Provider.user_id,services,propsal_rate,Communications]发布于 2012-12-08 15:49:50
在Yii中,如果我们通常使用STAT查询,那么查询的性能就会受到影响,因为STAT很慢。您可以在CDBCriteria select选项中使用COUNT来代替添加关系,为了使用它,我们需要将属性声明到模型中,就像在Serviceproposal模型中一样,您需要添加属性public $postCount;因此您可以使用out中的count值。
https://stackoverflow.com/questions/13775458
复制相似问题