空心我对我的表select m.voterID, sum(jm.mark) from marks mleft join marks jm on jm.id = m.idwhere 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`)
最佳答案
$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';
关于mysql - Yii CDb标准,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14894578/