如何纠正连接错误?

huangapple go评论98阅读模式
英文:

I'm new to sql language and am learning so I can help my organization out with pulling data. How would I go about correcting the join error?

问题

抱歉,以下是您要翻译的部分:

"You can see the error I am running into at the bottom.

I tried formatting the join command differently but cannot get it to work because it looks right."

如果您需要更多帮助,可以随时提出。

英文:

I have been trying to run this command for a couple days with no luck.

train> SELECT i.bill_cyc_cd, i.store_cd,
  2    SUM(CASE WHEN p.past_due_tp# > 0 AND p.past_due_tp# <= 4 THEN i.sch_pmt_amt ELSE 0 END) AS sch_pmt_amt,
  c.fname, c.lname, c.home_phone
FROM inst_cntr i
JOIN cntr$past_due_tp p ON i.cust_cd = p.cust_cd AND i.cntr_cd = p.cntr_cd
JOIN cust c ON i.cust_cd = c.cust_cd
WHERE i.bill_cyc_cd IN ('300', '150', '015', '030', '922', '921', '920')
  AND p.past_due_tp# > 0 AND p.past_due_tp# <= 4
  AND EXISTS (SELECT 1 FROM cntr$past_due_tp pd WHERE pd.cust_cd = i.cust_cd AND pd.cntr_cd = i.cntr_cd AND pd.past_due_tp# > 0 AND pd.past_due_tp# <= 4 AND pd.past_due_tp# IS NOT NULL)
GROUP BY i.bill_cyc_cd, i.store_cd, c.fname, c.lname, c.home_phone;
  3    4    5    6    7    8    9   10  JOIN cntr$past_due_tp p ON i.cust_cd = p.cust_cd AND i.cntr_cd = p.cntr_cd
*
ERROR at line 5:
ORA-00933: SQL command not properly ended

You can see the error I am running into at the bottom.

I tried formatting the join command differently but cannot get it to work because it looks right.

答案1

得分: 1

你在分组后加上分号,然后继续使用以下内容:

3 4 5 6 7 8 9 10

以及随机连接:

连接 cntr$past_due_tp p ON i.cust_cd = p.cust_cd AND i.cntr_cd = p.cntr_cd

这两个部分可以为您提供当前的错误。

传递此查询的理想方式是:

选择
i.bill_cyc_cd,
i.store_cd,
c.fname,
c.lname,
c.home_phone
SUM(CASE WHEN p.past_due_tp# > 0 AND p.past_due_tp# <= 4 THEN i.sch_pmt_amt ELSE 0 END) AS sch_pmt_amt,

inst_cntr i
连接 cntr$past_due_tp p ON i.cust_cd = p.cust_cd AND i.cntr_cd = p.cntr_cd
连接 cust c ON i.cust_cd = c.cust_cd
其中
i.bill_cyc_cd IN ('300', '150', '015', '030', '922', '921', '920')
并且 p.past_due_tp# > 0 AND p.past_due_tp# <= 4
并且存在 (
选择 1 从 cntr$past_due_tp pd
其中
pd.cust_cd = i.cust_cd
和 pd.cntr_cd = i.cntr_cd
和 pd.past_due_tp# > 0
和 pd.past_due_tp# <= 4
和 pd.past_due_tp# 不为空
)
分组依据
i.bill_cyc_cd,
i.store_cd,
c.fname,
c.lname,
c.home_phone

英文:

you end the group by at the ; and after that continue with the

3    4    5    6    7    8    9   10 

and the random join

JOIN cntr$past_due_tp p ON i.cust_cd = p.cust_cd AND i.cntr_cd = p.cntr_cd

these two things can provide you the current error

the ideal way to pass this query is

SELECT
 i.bill_cyc_cd,
 i.store_cd,
 c.fname,
 c.lname,
 c.home_phone
 SUM(CASE WHEN p.past_due_tp# &gt; 0 AND p.past_due_tp# &lt;= 4 THEN i.sch_pmt_amt ELSE 0 END) AS sch_pmt_amt,
FROM
 inst_cntr i
 JOIN cntr$past_due_tp p ON i.cust_cd = p.cust_cd AND i.cntr_cd = p.cntr_cd
 JOIN cust c ON i.cust_cd = c.cust_cd
WHERE
  i.bill_cyc_cd IN (&#39;300&#39;, &#39;150&#39;, &#39;015&#39;, &#39;030&#39;, &#39;922&#39;, &#39;921&#39;, &#39;920&#39;)
  AND p.past_due_tp# &gt; 0 AND p.past_due_tp# &lt;= 4
  AND EXISTS (
    SELECT 1 FROM cntr$past_due_tp pd
    WHERE
      pd.cust_cd = i.cust_cd
      AND pd.cntr_cd = i.cntr_cd
      AND pd.past_due_tp# &gt; 0
      AND pd.past_due_tp# &lt;= 4
      AND pd.past_due_tp# IS NOT NULL
    )
GROUP BY
  i.bill_cyc_cd,
  i.store_cd,
  c.fname,
  c.lname,
  c.home_phone

huangapple
  • 本文由 发表于 2023年3月7日 00:35:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75653439.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定