标准中的子查询 - 将mysql转换为具有相同表的yii CActiveDataProvider

时间:2014-01-22 17:28:26

标签: mysql yii

这将如何转换为yii CActiveDataProvider结构?!

SELECT t1.*
FROM data t1
WHERE t1.date= (SELECT MAX(t2.date)
 FROM data t2
 WHERE t2.fromNumber = t1.fromNumber)

由于

1 个答案:

答案 0 :(得分:3)

尝试此代码:未经测试。请检查。

希望您已为此表创建模型。在Model_name

的位置替换您的型号名称
$dataProvider=new CActiveDataProvider('Model_name', array(
            'criteria'=>array(
             'condition'=>'t.date = (SELECT MAX(t2.date)
                                     FROM data t2
                                     WHERE t2.fromNumber = t1.fromNumber)'
                       )
    )
    );

这有效:

        $dataProvider=new CActiveDataProvider('Data', array(
            'criteria'=>array(
                'condition'=>'t.date = (SELECT MAX(t2.date)
                FROM data t2
                WHERE t2.fromNumber = t.fromNumber)'),
            ));