$criteria->addAsColumn(“lastRow”, MAX(self::ID));给出错误?

发布于 2024-12-05 07:55:45 字数 1113 浏览 0 评论 0原文

我有这个代码:

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(自动增量字段),并且该字段是 ID 我也尝试过注释掉的行,但没有任何效果。我不知道如何实现这一目标..请帮忙? 谢谢

i have this code:

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);
}    

and get this error:

 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]

i just want the record of MAX(auto-increment-field) on the rc_message_box_table and this field is ID
i have tried the commented out lines as well but nothing works. i dont know how to achieve this..please help?
thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

姐不稀罕 2024-12-12 07:55:45

你的SQL中多了一个`,它从哪里来?它就在:

AS lastRow FROM rc_message_box_table`

There is an extra ` in your SQL, where does that come from? It is right next to:

AS lastRow FROM rc_message_box_table`
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文