Solved

how to sum the amount based on conditions ?

Posted on 2007-11-19
1
1,260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 74

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
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…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
Via a live example, show how to take different types of Oracle backups using RMAN.

696 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