MySQL 错误代码:1248。每个派生表都必须有自己的别名 No solution found for query

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27619026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:14:29  来源:igfitidea点击:

Error Code: 1248. Every derived table must have its own alias No solution found for query

mysqlsqlaliasderived-table

提问by shree.pat18

I am getting an error while using this query in MySQL.

在 MySQL 中使用此查询时出现错误。

The query logic is correct and I have tried it in Oracle and it's running fine, but I'm getting an error when running this in MySQL.

查询逻辑是正确的,我已经在 Oracle 中尝试过,并且运行良好,但是在 MySQL 中运行时出现错误。

I looked at previous questions on StackOverflow, but didn't find something to help me.

我在 StackOverflow 上查看了以前的问题,但没有找到可以帮助我的东西。

Here is the query:

这是查询:

select * from
  (select PM.ID, PM.Name, PM.TIMEOUT, PMS.PROCESS_MONITOR_ID, PMS.PROCESS_START_DATE
    from RATOR_IMP.PROCESS_MONITOR as PM
    JOIN RATOR_IMP.PROCESS_MONITOR_STATISTIC as PMS
    ON PM.ID = PMS.PROCESS_MONITOR_ID
    WHERE PM.ENABLED=1 and (PM.NAME='SDRRATINGENGINE11' or PM.NAME='WORKFLOWENGINE1')
    order by PMS.PROCESS_START_DATE desc)
limit 10000;

And here is the error:

这是错误:

Error Code: 1248. Every derived table must have its own alias 
No soultion found for query

回答by shree.pat18

You need to provide an alias for the subquery, like so:

您需要为子查询提供别名,如下所示:

select * from
(select PM.ID, PM.Name, PM.TIMEOUT, PMS.PROCESS_MONITOR_ID, PMS.PROCESS_START_DATE
 from RATOR_IMP.PROCESS_MONITOR as PM
 JOIN RATOR_IMP.PROCESS_MONITOR_STATISTIC as PMS
 ON PM.ID = PMS.PROCESS_MONITOR_ID
 WHERE PM.ENABLED=1 and (PM.NAME='SDRRATINGENGINE11' or PM.NAME='WORKFLOWENGINE1')
 order by PMS.PROCESS_START_DATE desc) as s
limit 10000;

From the documentation,

文档中

Subqueries are legal in a SELECT statement's FROM clause. The actual syntax is:

SELECT ... FROM (subquery) [AS] name ...

The [AS] name clause is mandatory, because every table in a FROM clause must have a name. Any columns in the subquery select list must have unique names.

子查询在 SELECT 语句的 FROM 子句中是合法的。实际语法是:

SELECT ... FROM (子查询) [AS] 名称 ...

[AS] name 子句是强制性的,因为 FROM 子句中的每个表都必须有一个名称。子查询选择列表中的任何列都必须具有唯一的名称。

回答by Abhik Chakraborty

Yes you need to specify an alias for the derived data

是的,您需要为派生数据指定别名

select x.* from
(select PM.ID, PM.Name, PM.TIMEOUT, PMS.PROCESS_MONITOR_ID, PMS.PROCESS_START_DATE
from RATOR_IMP.PROCESS_MONITOR as PM
JOIN RATOR_IMP.PROCESS_MONITOR_STATISTIC as PMS
ON PM.ID = PMS.PROCESS_MONITOR_ID
WHERE PM.ENABLED=1 and (PM.NAME='SDRRATINGENGINE11' or PM.NAME='WORKFLOWENGINE1')
order by PMS.PROCESS_START_DATE desc)x <-- here 
limit 10000;