【问题标题】:MySQL - How to add alias syntax to subqueryMySQL - 如何向子查询添加别名语法
【发布时间】:2011-01-28 18:42:20
【问题描述】:

我是 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

IN 子句有效:

SELECT batchid 
FROM (SELECT distinct batchid, date_format(uploaddate, '%Y-%m-%d') 
      FROM table1 
      WHERE uploaddate > '2011-01-26') AS t

我认为我的问题与第二个表别名有关。谁能告诉我我做错了什么?

【问题讨论】:

    标签: mysql mysql-error-1064 in-subquery


    【解决方案1】:

    WHERE 子句中出现的子查询不需要别名。

    去掉最后的AS t(就在分号之前),一切都会好起来的。

    【讨论】:

      猜你喜欢
      • 2019-03-09
      • 1970-01-01
      • 2021-02-03
      • 2015-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-10
      • 1970-01-01
      相关资源
      最近更新 更多