小编典典

错误代码:1248。每个派生表必须具有其自己的别名找不到用于查询的解决方案

sql

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

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

我查看了关于StackOverflow的先前问题,但没有找到什么对我有帮助。

这是查询:

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;

这是错误:

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

阅读 153

收藏
2021-03-23

共1个答案

小编典典

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

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;

文档中

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

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

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

2021-03-23