SQL语法问题(左连接)

发布于 2024-09-30 15:21:43 字数 871 浏览 10 评论 0原文

所以我在查询时遇到问题,但我不太明白问题出在哪里。语法错误的地方会加上注释。查询要大得多,我尝试缩短它以进行有效但更整洁的查询。

这是使用 odbc 连接到 Progress 数据库。我听说它使用严格的 SQL-92。

SELECT itemcust."item-cust", 
       itemcust."cust-no", 
       corptreeCust.code 

FROM      pub."item-cust" itemcust 
JOIN      pub.customer cust 
left join pub.salesstructcustomer struct 
     on ( struct."corp-cust-type" = cust."corp-cust-type" 
      and struct."corp-cust-num" = cust."corp-cust-num" 
     ) 
left join pub.corptree corptreeCust 
      on ( corptreeCust.uid = struct.corptreeid /* program says SQL Syntax error here */
       and corptreeCust.category = 'store' 
      ) 

where ( itemcust."in-entity" = {$entity} or itemcust."in-entity" = '*') 
  and itemcust."item-no" = {$itemno} 
  and ( itemcust."cust-no" = {$custno} or itemcust."cust-no" = '*') 
  and cust."cust-no" = {$custno}

谢谢!

So I'm having a problem with a query, and I don't really understand where. A comment is placed where the syntax error is. The query is much larger, I tried to shorten it to make a valid but tidier query.

This is using odbc to connect to a Progress database. I'm told it uses strict SQL-92.

SELECT itemcust."item-cust", 
       itemcust."cust-no", 
       corptreeCust.code 

FROM      pub."item-cust" itemcust 
JOIN      pub.customer cust 
left join pub.salesstructcustomer struct 
     on ( struct."corp-cust-type" = cust."corp-cust-type" 
      and struct."corp-cust-num" = cust."corp-cust-num" 
     ) 
left join pub.corptree corptreeCust 
      on ( corptreeCust.uid = struct.corptreeid /* program says SQL Syntax error here */
       and corptreeCust.category = 'store' 
      ) 

where ( itemcust."in-entity" = {$entity} or itemcust."in-entity" = '*') 
  and itemcust."item-no" = {$itemno} 
  and ( itemcust."cust-no" = {$custno} or itemcust."cust-no" = '*') 
  and cust."cust-no" = {$custno}

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小忆控 2024-10-07 15:21:43

pub.salesstructcustomer 的表别名是 struct,而不是联接中引用的 structc

Your table alias for pub.salesstructcustomer is struct, not structc as referenced in the join.

清旖 2024-10-07 15:21:43

这是一个错字吗?看起来它正在查看 structc 而不是 struct,除非我错过了一些东西。

Is that a typo? Looks like it's looking at structc instead of struct, unless I missed something.

醉态萌生 2024-10-07 15:21:43

您似乎在 cust 和 itemcust 之间没有 on 子句。这肯定会让解析器感到困惑,从而在查询中进一步抛出错误

You don't seem to have an on clause between cust and itemcust. That could certainly be confusing the parser into throwing an error further down the query

伪心 2024-10-07 15:21:43

首先,我感谢大家的回应。没有 ON 子句这一事实是一个严重的问题,但实际上并不是真正的问题。

问题实际上是 uid 是一个保留字,我必须将其设为 corptreeCust.\"uid\"

=(

First, I appreciate the responses. The fact that there was no ON clause was a serious issue, but it actually wasn't the real problem.

The problem actually was that uid is a reserved word, and I had to make it corptreeCust.\"uid\"

=(

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文