英文:
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# > 0 AND p.past_due_tp# <= 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 ('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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论