在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
您需要为子查询提供别名,如下所示:
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子句中的每个表都必须有一个名称。子查询选择列表中的任何列都必须具有唯一的名称。
子查询在SELECT语句的FROM子句中是合法的。实际语法为:
SELECT … FROM(子查询)[AS]名称…
[AS] name子句是强制性的,因为FROM子句中的每个表都必须有一个名称。子查询选择列表中的任何列都必须具有唯一的名称。