有一張桌子「公寓」。這裏需要在Yii中創建一個查詢。怎麼做?如何在Yii中使用union 2創建查詢?
SQL查詢:
SELECT *
FROM {{apartments}}
WHERE agent_id = 4
UNION
SELECT *
FROM {{apartments}}
WHERE agent_id != 4
在我cintroller
$arrSql[] = 'SELECT * FROM {{apartments}} WHERE agent_id=:agent_id';
$arrSql[] = 'SELECT * FROM {{apartments}} WHERE agent_id!=:agent_id';
$data = Apartments::model()->findAllBySql(implode(' UNION ', $arrSql), array(
':agent_id' => Yii::app()->user->id,
':status' => Apartments::STATUS_REMOVED
));
$dataProvider = new CArrayDataProvider($data);
但不工作分頁和過濾在我的窗口小部件CGridList。
您查詢是一樣'SELECT DISTINCT * FROM公寓;',不是嗎? –
[yii框架,如何實現union sql]可能的重複(http://stackoverflow.com/questions/12127908/yii-framework-how-to-implement-union-sql) – Dinistro
你想要什麼?你在做SELECT * FROM {{apartments}} – Sadikhasan