我对mysql还不熟悉,但它的语法仍然有问题。我有这样的疑问:
SELECT a, b, c, d, e
FROM table1
WHERE status = 'skipped'
AND batchid IN (SELECT batchid
FROM (SELECT distinct batchid, date_format(uploaddate, '%Y-%m-%d')
FROM table1
WHERE uploaddate > '2011-01-26') AS t
) AS t;
这就给了我一个错误:
ERROR 1064 (42000): 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 t' at line 1
条款工程:
SELECT batchid
FROM (SELECT distinct batchid, date_format(uploaddate, '%Y-%m-%d')
FROM table1
WHERE uploaddate > '2011-01-26') AS t
我认为我的问题与第二个表别名有关。有人能告诉我我做错了什么吗?
最佳答案
WHERE
子句中出现的子查询不需要别名。
去掉最后一个AS t
(在分号之前),一切都会好起来的。