这是我的代码。我不确定我做错了什么。该数据库名为inventory,该表名为data。我试图从名为check_up date的字段中的最早日期开始订购,并且最早拉出前两个。我想排除名称为“nobody”,“mainconf”和“testing”的用户:
SELECT user
FROM data
ORDER by checkup_date
WHERE data.name != "nobody"
AND WHERE data.name != "mainconf"
AND WHERE data.name != "testing" ASC
LIMIT 2
这是我的错误:
(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
\'WHERE data.name != "nobody" AND WHERE data.name != "mainconf" AND WHERE
data.nam\' at line 1')
答案 0 :(得分:2)
这些是错误:
ORDER BY
必须在WHERE
clausole之后和LIMIT
WHERE
时都不需要重复。只需写下AND
即可。答案 1 :(得分:2)
SELECT user
from data
WHERE name != "nobody" AND name != "mainconf" AND name != "testing"
ORDER by checkup_date ASC
limit 2
试试这个。
答案 2 :(得分:1)
排序稍后( WHERE 之后 LIMIT 之前):
SELECT user from data WHERE data.name != "nobody" AND data.name != "mainconf" AND data.name != "testing" ORDER by checkup_date ASC limit 2
答案 3 :(得分:1)
WHERE
子句需要在ORDER BY
子句之前。而且您只需要指定一次WHERE
子句。
SELECT user from data WHERE data.name != "nobody" AND data.name != "mainconf" AND data.name != "testing" ORDER by checkup_date ASC limit 2
答案 4 :(得分:1)
正确的MySQL语法是:
SELECT user from data WHERE data.name != "nobody" AND data.name != "mainconf" AND data.name != "testing" ORDER by checkup_date ASC LIMIT 2
每个AND之后不需要“WHERE”,ORDER BY需要在所有WHERE子句之后。
答案 5 :(得分:0)
这应该这样做
SELECT
user
FROM
data
WHERE
data.name != "nobody" AND data.name != "mainconf" AND data.name != "testing"
ORDER BY
checkup_date ASC
LIMIT 2