无效的标识符 SQL

Invalid Identifier SQL(无效的标识符 SQL)
本文介绍了无效的标识符 SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个:

SELECT p.plantnaam,o.levcode,o.offerteprijs
FROM plant p, offerte o
JOIN (SELECT plantcode , MIN(offerteprijs) AS offprijs 
      FROM offerte
      GROUP BY plantcode) s
  ON s.plantcode = p.plantcode
  AND s.offprijs = o.offerteprijs
ORDER BY p.plantnaam,l.levcode

显然在第 6 行,p.plantcode 突然神奇地变成了一个无效标识符.为什么是这样?为什么在此之前完全相同的表中的所有其他人都很好?

Appearently on the 6th row, p.plantcode is suddenly magically an invalid identifier. Why is this? and why are all the others from the exact same table perfectly fine before that point?

推荐答案

问题在于您正在混合 JOIN.您有隐式和显式连接.带有 ON 子句的显式 JOIN 语法比带有逗号的隐式连接具有更高的优先级.结果 plantofferte 表的别名在 ON 子句中将不可用.尝试在整个过程中使用相同的 JOIN 类型:

The problem is that you are mixing JOINs. You have both implicit and explicit joins. The explicit JOIN syntax with the ON clause has a higher precedence over the implicit join with the commas. As a result the alias for the plant and the offerte tables will not be available in the ON clause. Try using the same JOIN type throughout:

SELECT p.plantnaam, o.levcode, o.offerteprijs
FROM 
(
  SELECT plantcode , MIN(offerteprijs) AS offprijs 
  FROM offerte
  GROUP BY plantcode
) s
INNER JOIN plant p
   ON s.plantcode = p.plantcode
INNER JOIN offerte o
   ON s.offprijs = o.offerteprijs
ORDER BY p.plantnaam, l.levcode

这篇关于无效的标识符 SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

SQL to Generate Periodic Snapshots from Transactions Table(用于从事务表生成定期快照的SQL)
MyBatis support for multiple databases(MyBatis支持多个数据库)
Oracle 12c SQL: Missing column Headers in result(Oracle 12c SQL:结果中缺少列标题)
SQL query to find the number of customers who shopped for 3 consecutive days in month of January 2020(查询2020年1月连续购物3天的客户数量)
How to get top 10 data weekly (This week, Previous week, Last month, 2 months ago, 3 month ago)(如何每周获取前十大数据(本周、前一周、上个月、2个月前、3个月前))
Select the latest record for an Id per day - Oracle pl sql(选择每天ID的最新记录-Oracle pl SQL)