【发布时间】:2011-09-16 10:55:53
【问题描述】:
我有这个代码:
static public function getLastNewMessage($profile_id)
{
$c = new Criteria();
$subSelect = "rc_message_box_table.profile_id_from NOT IN ( SELECT rc_blocklist_table.profile_id_block FROM rc_blocklist_table WHERE profile_id = $profile_id ) and rc_message_box_table.profile_id_to=$profile_id and opened_once = 0";
$c->add(self::PROFILE_ID_TO, $subSelect, Criteria::CUSTOM);
$c->addAsColumn("lastRow", MAX(self::ID));
//$subSelect2 = "max(rc_message_box_table.id)";
//$c->add(self::ID, $subSelect2, Criteria::CUSTOM);
return self::doSelect($c);
}
并得到这个错误:
500 | Internal Server Error | PropelException [wrapped: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS lastRow FROM rc_message_box_table` WHERE rc_message_box_table.profile_id_fro' at line 1]
我只想要 rc_message_box_table 上的 MAX(auto-increment-field) 的记录,这个字段是 ID 我也尝试过注释掉的行,但没有任何效果。我不知道如何实现这一点..请帮忙? 谢谢
【问题讨论】:
-
我认为您需要将 MAX 用引号括起来:
$c->addAsColumn("lastRow", 'MAX( ' . self::ID . ' )');