我想計算一個列的計數另一個數字列的值的總和。我想要計算總和的特定列是'COUNT(d.totalcostofrent)。如何計算Oracle SQL中的計數列的總和?
我只是無法得到總共出現在桌子底下!
這裏是我的代碼:
COLUMN dummy NOPRINT
COMPUTE SUM OF totalcostofrent ON DUMMY
BREAK ON dummy
COLUMN branchname HEADING 'Branch Name'
COLUMN "Revenue" HEADING 'Rental Revenue' FORMAT $99,999
select null dummy,
a.branchname,
count(c.rentalid) "Number of Rentals",
SUM(d.totalcostofrent) "Revenue"
from branch a
inner join branchstaffrole b on a.branchid = b.branchid
inner join rental c on b.staffid = c.branchstaffid
inner join rentaltool d on c.rentalid = d.rentalid
where to_char(d.DATEOUT, 'YYYY') = '&Year'
group by a.branchname
order by 4 DESC;
Branch Name Number of Rentals Rental Revenue
-------------------- ----------------- --------------
Lichfield 2 $120
Stoke-on-Trent 3 $140
Birmingham 3 $155
Stafford 3 $225
我想它看起來就像這樣:
Branch Name Number of Rentals Rental Revenue
-------------------- ----------------- --------------
Lichfield 2 $120
Stoke-on-Trent 3 $140
Birmingham 3 $155
Stafford 3 $225
____
Sum $640
任何建議,將不勝感激!
不要UND erstand問題..你能舉一個你現在得到的結果的例子,以及你在找什麼? – Craig
我剛更新了帖子。 – Dan