Solved

how to sum the amount based on conditions ?

Posted on 2007-11-19
1
1,256 Views
Last Modified: 2013-12-19
I have a view called vw_invoice which has attributes amount, fiscal_key, splr_name, splr_id, adv_flag.

I need to sum all the amounts for current fiscal year, sum all the amounts for all the fiscal periods thus far -  by supplier,sum all the amounts
thus far for supplier where adv_flag is true, sum all the amounts for the current fiscal period where adv_flag is true.

eg: the output would be


splr_id , splr_name, address, amt_current_fiscal, sum_total, amt_current_fiscal_adv_flag, sum_total_adv_flag


1   tesname, houston, 100000.00, 20000000.00, 500000.00, 5430000.00


select splr_id, splr_name, sum(amount) as sum_total from vw_invoice
group by splr_id, splr_name --- this would get me current total amount how would I get the rest ?

the fiscal_key would be a parameter.
0
Comment
Question by:tech_question
1 Comment
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
ID: 20312667
SELECT   splr_id, splr_name, address,
         SUM(CASE
                 WHEN fiscal_key = :current_period
                     THEN amount
                 ELSE NULL
             END) amt_current_fiscal, SUM(amount) sum_total,
         SUM(CASE
                 WHEN fiscal_key = :current_period AND adv_flag = 'TRUE'
                     THEN amount
                 ELSE NULL
             END
            ) amt_current_fiscal_adv_flag,
         SUM(CASE
                 WHEN adv_flag = 'TRUE'
                     THEN amount
                 ELSE NULL
             END) sum_total_adv_flag
    FROM vw_invoice
GROUP BY splr_id, splr_name, address
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question