0

how to convert this query to Yii active record ?

SELECT a.USERID, a.ADID, a.PAGEVIEW,a.EXPIRYDATE,a.ADTITLE,a.ADDESC
        from CKAD a INNER JOIN 
        (
            SELECT  b.USERID, max(b.PAGEVIEW) as PAGEVIEW
            FROM CKAD b WHERE b.DISPPUBLISHDATE >= current_date - 3
            AND b.EXPIRYDATE >= current_date and b.STATUS = 1 AND b.USERID IS NOT NULL
            GROUP BY b.USERID
        ) b
        ON (a.USERID = b.USERID and a.PAGEVIEW = b.PAGEVIEW)
        order by a.PAGEVIEW DESC";
sasori
  • 5,249
  • 16
  • 86
  • 138
  • possible duplicate of [yii framework inner join](http://stackoverflow.com/questions/7190039/yii-framework-inner-join) – hakre Oct 18 '12 at 10:43
  • mine is using only one table ,it's different from the link you posted – sasori Oct 18 '12 at 10:59
  • Yours is using a join on a subselect. What about you convert that subselect into a [oracle view](http://stackoverflow.com/q/256700/367456)? Maybe then Yii is able to link to that "second" table? – hakre Oct 18 '12 at 11:00
  • Also please take not of this (mabye even better yet) duplicate: [Sub-queries ActiveRecord Yii](http://stackoverflow.com/q/8467698/367456) – hakre Oct 18 '12 at 11:03

0 Answers0