condition in criteria in yii framework php

前端 未结 2 1014
心在旅途
心在旅途 2021-01-23 01:44
$criteria=new CDbCriteria();
$criteria->with = array(\'reviewCount\', \'category10\', \'category20\', \'category30\', \'town\');
$criteria->select = \'t.id,busines         


        
2条回答
  •  轮回少年
    2021-01-23 02:21

    Maybe you could use a sub-select-query.

    For example in the select part of you criteria object:

    $criteria->select = 't.id,business,street,postalCode,contactNo,checkinCount,(select count(id) from tbl_abc where t.id=businessId) as spcount';
    

    Or as an inner join (which can also contain the "where spcount>1" condition):

    $criteria->join = 'join (select businessId, count(*) as spcount from tbl_abc) abc on t.id=abc.businessId and abc.spcount>1';
    

    In both scenarios spcount is also alvailable in the where-clause of your query. Also, "group by t.id" is not necessary anymore since spcount is now a single value for each row of the main table ("t").

    Hope this helps

提交回复
热议问题