空心我对我的表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`)
答案 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';