SQL查询中的语法错误。无法找到错误

时间:2018-06-06 22:56:04

标签: mysql sql ruby

我在mysql中为我的数据库编写测试。

con.query(“SELECT  `list`.* FROM `list`  WHERE `list`.`place` = 86 AND `list`.`person` = \"#{person_id}\" AND (( (list.state = 'open' AND num=\"#{num}\") || (list.state = ?) )) AND (list.updated_at > \"2018-06-05\") ORDER BY list.person, list.state='closed' DESC, list.updated_at DESC LIMIT 50 OFFSET 1”)

list是一个表格,numplaceperson是列表中单个项目的值。我也在红宝石脚本中使用它。

我收到语法错误。错误消息是:

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 ‘`?) )) AND (list.update_at > “2018-06-05”)) ORDER BY list.person, or`’

我无法弄清楚这个问题。请帮帮我。

2 个答案:

答案 0 :(得分:2)

查看查询的ORDER BY部分

ORDER BY list.person, list.state='closed' DESC, list.updated_at DESC 

list.state不应该有='已关闭'

只需尝试将其全部更改为

ORDER BY list.person, list.state DESC, list.updated_at DESC

答案 1 :(得分:-1)

我认为你在双引号中使用了错误的字符。你有。请改为"