0

我正在创建一个新报告,报告中只有一个光标,并且报告没有纸张布局(它直接转为 CSV 格式)。

我有一个查询,我需要在其中进行子查询,例如

SELECT
         grou.GROUP_ID                            GROUP_ID
         ,grou.group_name                          group_name
         ....
         (((SELECT SUM(nett_instalment_invoice_amount) 
            FROM instalments
            WHERE member_product_id = member_product_id)) subscription)
FROM

.... 等等....

在编译报告时我遇到一个错误说

Encountered Symbol SELECT while expecting one of the following symbols:
(  +  - 

如果不在最后添加 group by 子句,这可以得到帮助吗?

当我尝试通过放入 group by 子句并直接使用 sum 函数而不是 select (sum()) 来尝试另一种方法时。

请急需帮助。

谢谢。

4

4 回答 4

1

有一个简单的解决方法是创建一个函数,让我们称之为 get_installment_inv_sum 并带有一个参数 member_product_id,如下所示:

create or replace function get_installment_inv_sum (p_member_product_id number) return number
as 
 v_sum number
begin
 SELECT SUM(nett_instalment_invoice_amount) 
            into v_sum
            FROM instalments
            WHERE member_product_id = p_member_product_id;
 return v_sum;
end;

然后您可以调用您的选择,例如:

SELECT
         grou.GROUP_ID                            GROUP_ID
         ,grou.group_name                          group_name
         ....
         ,
         get_installment_inv_sum(member_product_id) subscription
FROM ...
于 2014-03-29T23:19:06.483 回答
0

哪个版本的 Oracle 报告?

标量子查询语法出现在 Oracle 8/8i 前后,但 Oracle 报告的开发在石器时代的某个时候停止了。过去 10 多年的许多增强型 SQL 语法都没有实现。

如果您可以将大部分查询创建为数据库中的视图,并且只需从报表中的视图中进行选择,那么您将具有更大的灵活性

于 2011-03-17T23:46:26.813 回答
0
SELECT /*+ ORDERED PUSH_SUBQ*/
          11
         ,'SQ'
         ,grou.GROUP_ID                            GROUP_ID
         ,grou.group_name                          group_name
         ,intm.intermediary_id                     intermediary_id          --R3352 AUS Regulatory added new field
         ,intm.intermediary_name                   intermediary_name 
         ,regi.registration_id                     registration_id
         ,mere.member_id                           member_id
         ,memb.title_code                          title_code
         ,memb.given_name||' '||memb.family_name   member_name
         --,mech.birth_date                          birth_date
         ,mere.company_employee_ref                company_employee_ref
         ,memb.orig_risk_start_date                orig_risk_start_date
         ,mere.original_bi_joining_date            orig_joining_date
         ,mepr.member_product_id                   member_product_id
         ,mepr.member_product_risk_start_date      mp_risk_start_date
         ,mepr.product_id                          product_id
         ,INITCAP(prod.product_name)               product_name
         ,cont.currency_code
         ,mere.customer_status_code
         /* ,((SELECT SUM(inst.nett_instalment_invoice_amount) 
            FROM instalments inst
            WHERE inst.member_product_id = mepr.member_product_id)) subscription */
         ,SUM(inst.nett_instalment_invoice_amount) subscription
  FROM    registrations                 regi
         ,member_registrations          mere
         ,member_products               mepr
         ,contracts                     cont
         ,products                      prod
         ,members                       memb
         ,groups                        grou
         ,intermediaries                intm
         ,insurers                      insu        
         ,instalments                   inst
  WHERE  insu.insurer_id                = i_insurerid
  AND    NVL(i_reportdate  ,Sysdate)    >= cont.contract_risk_start_date
  AND   NVL(i_reportdate  ,Sysdate)     < cont.renewal_date      
  --AND    regi.GROUP_ID                   IN (77648,77658) --Arv
  AND    prod.insurer_id                 = insu.insurer_id(+)
  AND    mere.member_id                  = memb.member_id
  AND    mere.member_id                  = mepr.member_id
  AND    mepr.contract_pk                = cont.contract_pk
  AND    mepr.product_id                 = prod.product_id(+)
  AND    mepr.intermediary_id            = intm.intermediary_id(+)
  AND    mere.registration_id            = regi.registration_id 
  AND    mere.registration_id            = mepr.registration_id
  AND    regi.GROUP_ID                   = grou.group_id 
  AND    inst.member_product_id          = mepr.member_product_id
  AND    grou.group_level_code       IN ('G','R')
  AND    mere.customer_status_code       IN ('A','L')      
  AND    family_name_uppercase          <> UPPER('zz** Please Ignore This Member **zz') 
  AND    given_name_uppercase           <> UPPER('zz** Please Ignore **zz') --l_given_name_uppercase

    AND    NOT EXISTS
         ( SELECT 'X'
           FROM   customer_lapses
           WHERE  GROUP_ID               = regi.GROUP_ID
           AND    suspend_lapse_ind      = 'L'
           AND    reinstatement_ind      = 'N'
           AND    lapse_effective_date  <= NVL(i_reportdate  ,Sysdate)
           UNION
           SELECT 'X'
           FROM   customer_lapses
           WHERE  registration_id        = regi.registration_id
           AND    suspend_lapse_ind      = 'L'
           AND    reinstatement_ind      = 'N'
           AND    lapse_effective_date  <= NVL(i_reportdate  ,Sysdate)
         )

  AND    NOT EXISTS
         ( SELECT 'X'
           FROM   customer_lapses
           WHERE  mem_reg_member_id        = mere.member_id
           AND    mem_reg_registration_id  = mere.registration_id
           AND    suspend_lapse_ind        = 'L'
           AND    reinstatement_ind        = 'N'
           AND    lapse_effective_date    <= NVL(i_reportdate  ,Sysdate)
         )

  AND    NOT EXISTS
         ( SELECT 'X'
           FROM   customer_lapses
           WHERE  member_product_id        = mepr.member_product_id
           AND    suspend_lapse_ind        = 'L'
           AND    reinstatement_ind        = 'N'
           AND    lapse_effective_date    <= NVL(i_reportdate  ,Sysdate)
           UNION
           SELECT 'X'
           FROM   customer_lapses
           WHERE  cust_prod_contract_pk    = mepr.contract_pk
           AND    cust_prod_product_id     = mepr.product_id
           AND    suspend_lapse_ind        = 'L'
           AND    reinstatement_ind        = 'N'
           AND    lapse_effective_date    <= NVL(i_reportdate  ,Sysdate)
         )

         Group BY    11
         ,'SQ'
         ,grou.GROUP_ID                           -- GROUP_ID
         ,grou.group_name                         -- group_name
         ,intm.intermediary_id                    -- intermediary_id          --R3352 AUS Regulatory added new field
         ,intm.intermediary_name                  -- intermediary_name 
         ,regi.registration_id                  --   registration_id
         ,mere.member_id                         --  member_id
         ,memb.title_code                        --  title_code
         ,memb.given_name||' '||memb.family_name  -- member_name
         --,mech.birth_date                          birth_date
         ,mere.company_employee_ref               -- company_employee_ref
         ,memb.orig_risk_start_date              --  orig_risk_start_date
         ,mere.original_bi_joining_date          --  orig_joining_date
         ,mepr.member_product_id                 --  member_product_id
         ,mepr.member_product_risk_start_date     -- mp_risk_start_date
         ,mepr.product_id                         -- product_id
         ,INITCAP(prod.product_name)              -- product_name
         ,cont.currency_code
         ,mere.customer_status_code
于 2011-03-17T13:36:42.410 回答
0

这当然是允许的:

select d.dname, (sum(e.sal) from emp e where e.deptno = d.deptno) as dept_sal
from dept d;

这是这样的:

select d.dname, sum(e.sal)
from dept d
left outer join emp e on e.deptno = d.deptno
group by d.dname;

那么你具体做了什么?

于 2011-03-17T12:58:33.857 回答