PDOException:SQLSTATE [42000]

时间:2019-07-30 12:13:27

标签: mysql sql

  

致命错误:未捕获的PDOException:SQLSTATE [42000]:语法错误或   访问冲突:1064您的SQL语法错误;检查   与您的MySQL服务器版本相对应的手册   在'AND Sold = 0 ORDER BY Date DESC,Count DESC,Price附近使用的语法   1026行{path}中第14行的ASC'

查询:

select * from (numbers t inner join (select distinct n.Number
from (
  select 1 start union all select 2  union all select 3 union all 
  select 4 union all select 5 
) s cross join numbers n
where 
  left(substring(n.Number, s.start, 2), 1) <> right(substring(n.Number, s.start, 2), 1)
  and
  n.Number like concat(
    '%', substring(n.Number, s.start, 2), 
    substring(n.Number, s.start, 2),
    substring(n.Number, s.start, 2),
    substring(n.Number, s.start, 2), '%'
  )) n on n.Number = t.Number) AND Sold = 0 ORDER BY Date DESC,Count DESC,Price ASC

2 个答案:

答案 0 :(得分:0)

numbers t .... and SOLD = 0之前,您似乎输入了错误的几对

select * 
from numbers t 
inner join (select distinct n.Number
  from (
    select 1 start 
    union all select 2  
    union all select 3 
    union all select 4 
    union all select 5 
) s 
cross join numbers n
where 
  left(substring(n.Number, s.start, 2), 1) <> right(substring(n.Number, s.start, 2), 1)
  and
  n.Number like concat(
    '%', substring(n.Number, s.start, 2), 
    substring(n.Number, s.start, 2),
    substring(n.Number, s.start, 2),
    substring(n.Number, s.start, 2), '%'
  )) n on n.Number = t.Number AND Sold = 0 
  ORDER BY Date DESC,Count DESC,Price ASC

无论如何都要进行几个嵌套的子查询,以检查我的建议是否确实有用

答案 1 :(得分:0)

错误正在附近显示-“已售出”,所以在完成查询后,您没有启动“ where”子句。添加“ Where”子句,然后写下您的条件