我在PostgreSQL中编写了一个查询,该查询工作正常但在Oracle SQL中执行时不起作用。我很累,试图找出问题所在。请帮我解决。
SELECT tb1.executive_code,tb1.month,tb1.year,tb1.count_req_no,
t1.count_enquiry_closed,tb1.sum_exp_amt,tb1.sum_trr_exp_tenure,
tb1.sum_exp_tenure,t1.avg_total_case_tat,tb1.count_finance_amt,
tb1.count_mls,t1.count_rejection_negative,t1.count_dedupe_date,
t1.count_rejection_pre,t1.count_fi_feedback_date,
t1.count_rejection_fi,t1.count_ready_date
FROM (
SELECT dealing_executive_code AS executive_code,
date_part('month',tb.req_date) AS month,
date_part('year',tb.req_date) AS year,
count(tb.req_no) AS count_req_no,
dealing_executive_code,sum(tb.exp_amt) AS sum_exp_amt,
sum(tb.tent_net_irr_cost_all_payout*tb.exp_amt*tb.tenure) AS sum_trr_exp_tenure,
sum(tb.exp_amt*tb.tenure) AS sum_exp_tenure,
count(case when insurance_finance_amt !='0' then '1' end ) AS count_finance_amt,
count(case when mls_finance_amount !='0' then '1' end ) AS count_mls
FROM tb_requisition_report AS tb
GROUP BY date_part('month',tb.req_date),date_part('year',tb.req_date),
tb.dealing_executive_code
) AS tb1
LEFT JOIN (
SELECT date_part('month',enq_date) AS d1,
date_part('year',enq_date) AS d2,
count(case when enquiry_status='CLOSED' then '1' end )AS count_enquiry_closed,
dealing_executive_code,avg(total_case_tat) AS avg_total_case_tat,
count(case when lost_rejection_stage='NEGATIVE DEDUPE STAGE' then '1' end) AS count_rejection_negative,
count(case when dedupe_date IS NOT NULL then '1' end) AS count_dedupe_date,
count(case when lost_rejection_stage='PRE SANCTION DOCUMENT PENDIN' then '1' end) AS count_rejection_pre,
count(case when fi_feedback_date IS NOT NULL then '1' end) AS count_fi_feedback_date,
count(case when lost_rejection_stage='FI NEGATIVE CLEARANCE STAGE' then '1' end) AS count_rejection_fi,
count(case when fi_ready_date IS NOT NULL then '1' end) AS count_ready_date
FROM tb_lead_tracker
GROUP BY date_part('month',enq_date),date_part('year',enq_date),
dealing_executive_code
) AS t1
ON t1.dealing_executive_code=tb1.dealing_executive_code
AND t1.d1=tb1.month AND t1.d2=tb1.year
答案 0 :(得分:1)
您不能将AS
用于Oracle中的表别名,仅用于列别名。例如,这个:
FROM tb_requisition_report AS tb
......必须是:
FROM tb_requisition_report tb
和其他内联视图相同。目前解析器将AS
视为不长的东西,并且它经常会回到ORA-00907 - 它通常不会。 t意味着实际上存在一个不平衡的括号,只是找不到它的位置,这通常是因为另一个语法错误。解析器无法解释您的意图,因此无法更加明确错误,尤其是涉及其他关键字时。
Sathya已经提到,在评论中,datepart
不是内置的Oracle功能,因此可能无法解决您的所有问题。