Php Yii框架迁移

Php Yii框架迁移,php,sql,yii,sql-update,Php,Sql,Yii,Sql Update,所以,基本上我想要的是制作一个文件,对我的数据库进行一些更改。我必须输入一些数据,但为了更快,我想使用SQLIn操作符。所以我想要的应该是这样的: $this->update('basicInfo', array('regionId' => 1), 'WHERE countyId IN (SELECT id FROM countyTable WHERE regionId = 1 )') // retrieve county ids for regionId = 1 $dbConn

所以,基本上我想要的是制作一个文件,对我的数据库进行一些更改。我必须输入一些数据,但为了更快,我想使用SQLIn操作符。所以我想要的应该是这样的:

$this->update('basicInfo', array('regionId' => 1), 
'WHERE countyId IN (SELECT id FROM countyTable WHERE regionId = 1 )')
// retrieve county ids for regionId = 1
$dbConn         = $this->getDbConnection();
$countyTableIds = $dbConn->createCommand()
    ->select('id')
    ->from('countyTable')
    ->where('regionId = 1')
    ->queryAll();

// prepare condition as array. 
$condition = array('in', 'countyId', $countyTableIds);

// update
$this->update('basicInfo', array('regionId' => 1), $condition);
当countyId为3、6、7、9、4等时,regionId应设置为1

我知道这不起作用,但我不知道如何使其起作用,是否有可能使其起作用。

有关如何使用sql“in”条件的详细信息

我会这样做:

$this->update('basicInfo', array('regionId' => 1), 
'WHERE countyId IN (SELECT id FROM countyTable WHERE regionId = 1 )')
// retrieve county ids for regionId = 1
$dbConn         = $this->getDbConnection();
$countyTableIds = $dbConn->createCommand()
    ->select('id')
    ->from('countyTable')
    ->where('regionId = 1')
    ->queryAll();

// prepare condition as array. 
$condition = array('in', 'countyId', $countyTableIds);

// update
$this->update('basicInfo', array('regionId' => 1), $condition);
使用ANY子句

UPDATE mytable
    SET status = 'inactive'
  WHERE countyId = ANY (SELECT id FROM countyTable WHERE regionId = 1 )

非常感谢。工作得很有魅力