做一些SQL并试图安排我的数据。我做了代码等但是我得到了#1064错误(语法问题)有人可以检查我的代码并告诉我哪里错了:)
$database = new connection();
$database = $database->Connect("companyhouse");
$statement = $database->prepare(" SELECT *
FROM companyhouse_23
ORDER BY Incorporation_Date DESC
WHERE
incorporation_date >= NOW() - INTERVAL 3 MONTH
AND County = 'Sussex'
AND County LIKE '%Sussex%'
");
$statement->execute();
$Results = $statement->fetchall(PDO::FETCH_OBJ);
在我看来,这一切都很好,但显然不是吗?哈哈
答案 0 :(得分:2)
您之前使用Order By
子句而不是Where
子句。 Order By
子句必须是任何查询的最后一个子句。说得对。
答案 1 :(得分:1)
$statement = $database->prepare(" SELECT
*
FROM
companyhouse_23
WHERE
incorporation_date >= NOW() - INTERVAL 3 MONTH
AND County = 'Sussex'
AND County LIKE '%Sussex%'
ORDER BY
Incorporation_Date DESC
");
答案 2 :(得分:1)
像这样重新排列查询。 ORDER BY
之后应使用WHERE
SELECT
*
FROM
companyhouse_23
WHERE
incorporation_date >= NOW() - INTERVAL 3 MONTH
AND County = 'Sussex'
AND County LIKE '%Sussex%'
ORDER BY
Incorporation_Date DESC
答案 3 :(得分:0)
SELECT *
FROM companyhouse_23
WHERE incorporation_date >= NOW() - INTERVAL 3 MONTH
AND County='Sussex'
AND County LIKE '%Sussex%'
ORDER BY Incorporation_Date DESC
您的查询中需要注意的两件事: