gpt4 book ai didi

MySQL - 如何将别名语法添加到子查询

转载 作者:可可西里 更新时间:2023-11-01 07:33:41 25 4
gpt4 key购买 nike

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

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

最佳答案

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

去掉最后的 AS t(就在分号之前),一切都应该没问题。

关于MySQL - 如何将别名语法添加到子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4831862/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com