简体   繁体   中英

Get the sum of a column in oracle reports

I am trying to get the sum of a column using oracle reports, but with a condition. For example I have three columns, a store column, a fruit column and a cost column. I want to get the sum cost of all the "bananas", or whichever fruit you pick, bought in a particular store.

Ex:

store1------------banana----------------$5.00

store1------------apple-----------------$2.00

store1------------banana----------------$3.50

store 1 bananas = $8.50 <- this is what I want

store 1 sum = $10.50

store2------------apples----------------$1.50 etc

I've tried making a formula in the data model, but then I'd have to supply it with the store name.

You can use the SUM function, wich is a ANSI SQL function. You also need to use group by:

select store_name, fruit_name, sum(cost)as Total_Cost
from your_table
group by store_name, fruit_name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM