oracle 在同一列中显示两个计算

dgsult0t  于 2023-04-29  发布在  Oracle
关注(0)|答案(1)|浏览(130)

我写了这段代码,并希望它在同一列和不同的行中显示两个计算:

COMPUTE COUNT LABEL 'Total Item :' OF subtotal on memberID 
COMPUTE SUM  LABEL 'Total (Yen): ' OF subtotal ON memberID

结果是它只显示第二个计算,而不显示第一个计算

Total (Yen)      $1137.50

结果应该是

Total Item :      2
Total (Yen):      $1137.50
zujrkrfu

zujrkrfu1#

必须在同一语句中定义这两个计算。

break on memberid skip 1

compute count label 'Total Items:' sum label 'Total (Yen):' of subtotal on memberID 

col memberid format a12
col subtotal format $9990D00

确认SQL*Plus如何理解您的命令:

SQL> comp
COMPUTE count LABEL 'Total Items:' sum LABEL 'Total (Yen):' OF subtotal ON memberID
with demo (memberid, subtotal) as
    ( select 'ABCD', 1.2 from dual union all
      select 'ABCD', 2.3 from dual union all
      select 'DEFG', 4.5 from dual union all
      select 'DEFG', 6.7 from dual union all
      select 'DEFG', 8.9 from dual union all
      select 'WXYZ', 0.1 from dual union all
      select 'WXYZ', 2.3 from dual )
select memberid, subtotal from demo
order by 1, 2;
MEMBERID      SUBTOTAL
------------ ---------
ABCD             $1.20
                 $2.30
************ ---------
Total Items:         2
Total (Yen):     $3.50

DEFG             $4.50
                 $6.70
                 $8.90
************ ---------
Total Items:         3
Total (Yen):    $20.10

WXYZ             $0.10
                 $2.30
************ ---------
Total Items:         2
Total (Yen):     $2.40

7 rows selected.

要添加总计,请执行以下操作:

break on memberid skip 1 on report

compute count label 'Total Items:' sum label 'Total (Yen):' of subtotal on memberID report
MEMBERID      SUBTOTAL
------------ ---------
ABCD             $1.20
                 $2.30
************ ---------
Total Items:         2
Total (Yen):     $3.50

DEFG             $4.50
                 $6.70
                 $8.90
************ ---------
Total Items:         3
Total (Yen):    $20.10

WXYZ             $0.10
                 $2.30
************ ---------
Total Items:         2
Total (Yen):     $2.40

             ---------
Total Items:         7
Total (Yen):    $26.00

7 rows selected.

相关问题