Filtering by an aggregate function is done in the HAVING clause, because it’s executed after computing the aggregate value. Set that condition in the ‘having’ property of criteria object.
I just replaced $criteria->condition to $criteria->having then while am trying to generate the cgridview details there am getting the total count is different, means below please find the two related queries which yii executing while calling the cgrdiview
For getting the count
Querying SQL: SELECT COUNT(DISTINCT `t`.`ID`) FROM `tbltransactions` `t`
LEFT OUTER JOIN `tblusers` `user` ON (`t`.`UserID`=`user`.`ID`) LEFT OUTER
JOIN `tbluser_info` `userInfos` ON (`userInfos`.`UserID`=`user`.`ID`)
For getting the data this is the query
SQL: SELECT sum(Amount) as Amt FROM `tbltransactions` `t` LEFT
OUTER JOIN `tblusers` `user` ON (`t`.`UserID`=`user`.`ID`) LEFT OUTER JOIN
`tbluser_info` `userInfos` ON (`userInfos`.`UserID`=`user`.`ID`) GROUP BY
t.UserID HAVING (Amt>=userInfos.WithdrawalValue) LIMIT 10
both query is different…how it is happening in my code i am writing the the second query… for getting the count yii generating the query… why yii generating different using different crietera for getting the count and data.Please advise…