【问题标题】:$criteria->addAsColumn("lastRow", MAX(self::ID)); gives error?$criteria->addAsColumn("lastRow", MAX(self::ID));给出错误?
【发布时间】: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 . ' )');

标签: php symfony1 propel


【解决方案1】:

您的 SQL 中有一个额外的 `,这是从哪里来的?它就在旁边:

AS lastRow FROM rc_message_box_table`

【讨论】:

  • 这里是完整的错误:[wrapped: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“AS lastRow FROM rc_message_box_table WHERE rc_message_box_table.profile_id_fro”附近使用正确的语法]
猜你喜欢
  • 2013-04-09
  • 1970-01-01
  • 1970-01-01
  • 2020-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多