0

空心我对我的桌子有一种查询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`)
4

1 回答 1

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';
于 2013-02-15T16:44:55.130 回答