2

計算合計を使用してSQLテーブルの問題を理解するのに苦労しています。

列の合計があるはずの場所に表示されるのは、空白のボックスだけです。

以下のコード:

TTITLE CENTER ==================== SKIP 1-
CENTER 'U  T O O L' skip 1-
CENTER ==================== SKIP 1 - 
LEFT 'Tool Report 1.03' SKIP 1 -
LEFT ============ SKIP 2-
RIGHT 'Page:' -
FORMAT 999 SQL.PNO SKIP 2 

set pagesize 50

column MEMBERNAME HEADING 'Member Name'  format a20


compute sum of TOTAL on Rental_ID
Break on RENTAL_ID
select Member.Member_ID, SUBSTR(Member.FName,0,10) || SUBSTR(' ',0,10) ||
SUBSTR(Member.SName,0,15) as MEMBERNAME,
Rental.Rental_ID,
Tool.Name, 
Rental_Line.Qty,
Rental_Line.Price,
TO_Char(Rental_Line.Qty*Rental_Line.Price,'L9,999.99') TOTAL
from Rental_Line
INNER JOIN Rental
on Rental.Rental_ID = Rental_Line.Rental_ID
INNER JOIN Member
on Rental.Member_ID = Member.Member_ID
INNER JOIN Tool_Instance
on Rental_Line.Tool_Instance_ID = Tool_Instance.Tool_Instance_ID
INNER JOIN Tool
on Tool_Instance.Tool_ID = Tool.Tool_ID
where Rental.Rental_ID = '&Rental_ID';
4

1 に答える 1

0

SUM(Rental_Line.Qty)OVER(PARTITION BY Rental.Rental_ID)が必要だと理解したので、これが役立つかもしれません。

select Member.Member_ID,
       SUBSTR(Member.FName, 0, 10) || SUBSTR(' ', 0, 10) ||
       SUBSTR(Member.SName, 0, 15) as MEMBERNAME,
       Rental.Rental_ID,
       Tool.Name,
       Rental_Line.Qty,
       Rental_Line.Price,
       TO_Char(Rental_Line.Qty * Rental_Line.Price, 'L9,999.99') TOTAL,
       SUM(Rental_Line.Qty) OVER (PARTITION BY Rental.Rental_ID) TOTAL_QTY,
       SUM(Rental_Line.Qty * Rental_Line.Price) OVER (PARTITION BY Rental.Rental_ID) TOTAL_SUM
  from Rental_Line
 INNER JOIN Rental on Rental.Rental_ID = Rental_Line.Rental_ID
 INNER JOIN Member on Rental.Member_ID = Member.Member_ID
 INNER JOIN Tool_Instance on Rental_Line.Tool_Instance_ID =
                             Tool_Instance.Tool_Instance_ID
 INNER JOIN Tool on Tool_Instance.Tool_ID = Tool.Tool_ID
 where Rental.Rental_ID = '&Rental_ID';
于 2012-11-29T06:04:18.047 に答える