Yii CDbCriteria

时间:2013-02-15 12:16:23

标签: mysql activerecord yii

空心我对我的表select m.voterID, sum(jm.mark) from marks m left join marks jm on jm.id = m.id where jm.voterID in (1,2) group by m.voterID

有一些疑问

我不明白如何使用CDbCriteria进行操作。 表结构是

 `id` int(11) NOT NULL AUTO_INCREMENT,
  `voterId` int(11) NOT NULL,
  `votedId` int(11) NOT NULL,
  `mark` int(11) NOT NULL,
  `creation_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)

1 个答案:

答案 0 :(得分:1)

$criteria = new CDbCriteria();
$criteria->select = 'm.voterID, sum(jm.mark)';
$criteria->from = 'marks m';
$criteria->join = 'left join marks jm on jm.id = m.id';
$criteria->condition = 'jm.voterID in (1,2)';
$criteria->group = 'm.voterID';