首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用统计查询关联3个或更多表

使用统计查询关联3个或更多表
EN

Stack Overflow用户
提问于 2012-12-08 15:21:25
回答 1查看 218关注 0票数 0

我正在尝试使用统计查询来关联Yii中的3个表。我需要显示每个请求的最低速率,由登录用户发布的条件,其中“通信”=海和“国家”=中国,其中通信和国家是3个不同的表的属性。我如何实现这一点?在统计查询的情况下,有没有添加AND/Or的方法?我的代码如下所示。

代码语言:javascript
复制
   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"'),
                    );

数据库:

代码语言:javascript
复制
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]
EN

回答 1

Stack Overflow用户

发布于 2012-12-08 15:49:50

在Yii中,如果我们通常使用STAT查询,那么查询的性能就会受到影响,因为STAT很慢。您可以在CDBCriteria select选项中使用COUNT来代替添加关系,为了使用它,我们需要将属性声明到模型中,就像在Serviceproposal模型中一样,您需要添加属性public $postCount;因此您可以使用out中的count值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13775458

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档