Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用统计查询关联3个或更多表_Php_Mysql_Phpmyadmin_Yii - Fatal编程技术网

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

Php 使用统计查询关联3个或更多表,php,mysql,phpmyadmin,yii,Php,Mysql,Phpmyadmin,Yii,我正在尝试使用统计查询将Yii中的3个表关联起来。我需要显示登录用户发布的每个请求的最低速率,条件是“通信”=hai,“国家”=China,其中通信和国家是3个不同表的属性。我如何实现这一点?在统计查询的情况下,是否有添加和/或的方法。我的代码如图所示 return array( 'serviceproposals' => array(self::HAS_MANY, 'Servicepropo

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

   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]

在Yii中,若我们使用STAT查询,通常查询的性能会受到影响,因为STAT很慢。您可以在CDBCriteria选择选项中使用COUNT,而不是添加关系,要使用它,我们需要将该属性声明到模型中
像在Serviceproposal模型中一样,您需要添加属性public$postCount;因此,您可以使用count from out的值

@bool.dev我如何在统计查询中实现这一点有没有办法在“'minvalue'=>数组(self::STAT,'serviceproval','ServiceRequestID','select'=>'MIN(提案金额)','condition'=>'Communications=“hai”')中添加对条件的更改,`对于添加第三个表,您是使用CDbCriteria还是仅使用关系?如果使用CDbCriteria,所有问题都将得到解决。只需要在关系方面做点工作。在这里,您需要添加选择参数$criteria=new CDbCriteria()$条件->选择=“选择最小(建议金额)作为最小建议金额”$条件->条件=”;但是别名应该在模型类Serviceproposal Extendes ActiveRecordModel{public$min_proposal_amount;}中声明