aggregation of the amount

Oracle 10g version

Hi all
can you please help me to get the sum of gift_amount (group by id, organization).
If the gift_type = cumilative then do not consider the present previous record years for the aggregation.
CREATE TABLE CUMILATIVE_TEST
(
  ID            NUMBER,
  GIFT_TYPE     VARCHAR2(30 BYTE),
  GIFT_AMOUNT   NUMBER,
  GIFT_YEAR     VARCHAR2(4 BYTE),
  ORGANIZATION  VARCHAR2(110 BYTE)
);

SET DEFINE OFF;
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Cumulative', 25000, '2004', 'Southern Seminary');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Gift', 25000, '2002', 'Southern Seminary');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Cumulative', 25000, '2001', 'Southern Seminary');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Gift', 25000, '2006', 'Southern Seminary');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Gift', 25000, '2007', 'Southern Seminary');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Gift', 25000, '2003', 'Southern Seminary');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Individual', 100, '2002', 'The Colonial Williamsburg Foundation');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Individual', 2000, '2007', 'The Medical Foundation Of North Carolina');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Individual', 250, '1996', 'The Peabody Institute of The John Hopkins University');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Monetary', 200000, '2006', 'University Of California Berkeley Haas School Of Business');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Monetary', 5000, '2006', 'University Of Miami');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Monetary', 100, '2006', 'University Of North Carolina Cancer Center');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Monetary', 500, '2005', 'University Of Virginia Mcintire School Of Commerce');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Corporation', 2000, '1996', 'University of Florida Foundation');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Individual', 5000, '2004', 'University of Miami');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Individual', 25000, '2002', 'University of South Carolina');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Individual', 5000, '2002', 'University of South Carolina');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Monetary', 100, '2008', 'Vcu Massey Cancer Center');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Monetary', 250, '2008', 'Vcu Massey Cancer Center');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Monetary', 100, '2006', 'Virginia Home For Boys And Girls');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Monetary', 100, '2005', 'Virginia Home For Boys And Girls');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Monetary', 500, '2005', 'Virginia Home For Boys And Girls');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Individual', 1, '2003', 'Virginia Museum of Fine Arts');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Individual', 500, NULL, 'WHYY-TV');
Insert into CUMILATIVE_TEST
   (ID, GIFT_TYPE, GIFT_AMOUNT, GIFT_YEAR, ORGANIZATION)
 Values
   (1992, 'Monetary', 1, '2002', 'Wake Forest University');
COMMIT;

select * from cumilative_test order by organization, gift_year;

For organization Southern Seminary we need to ignore the first three records ,
 because for the year 2004 cumilative amount is received
Published by: new learning on January 24, 2011 10:45
select  id,
        gift_type,
        gift_amount,
        gift_year,
        organization
  from  (
         select  a.*,
                 max(case gift_type when 'Cumulative' then gift_year end) over(partition by organization) last_cumulative_year
           from  cumilative_test a
        )
  where gift_year >= last_cumulative_year
     or last_cumulative_year is null
/

         ID GIFT_TYPE       GIFT_AMOUNT GIFT ORGANIZATION
----------- --------------- ----------- ---- ------------------------------------------------------------
       1992 Cumulative            25000 2004 Southern Seminary
       1992 Gift                  25000 2006 Southern Seminary
       1992 Gift                  25000 2007 Southern Seminary
       1992 Individual              100 2002 The Colonial Williamsburg Foundation
       1992 Individual             2000 2007 The Medical Foundation Of North Carolina
       1992 Individual              250 1996 The Peabody Institute of The John Hopkins University
       1992 Monetary             200000 2006 University Of California Berkeley Haas School Of Business
       1992 Monetary               5000 2006 University Of Miami
       1992 Monetary                100 2006 University Of North Carolina Cancer Center
       1992 Monetary                500 2005 University Of Virginia Mcintire School Of Commerce
       1992 Corporation            2000 1996 University of Florida Foundation

         ID GIFT_TYPE       GIFT_AMOUNT GIFT ORGANIZATION
----------- --------------- ----------- ---- ------------------------------------------------------------
       1992 Individual             5000 2004 University of Miami
       1992 Individual            25000 2002 University of South Carolina
       1992 Individual             5000 2002 University of South Carolina
       1992 Monetary                100 2008 Vcu Massey Cancer Center
       1992 Monetary                250 2008 Vcu Massey Cancer Center
       1992 Monetary                100 2006 Virginia Home For Boys And Girls
       1992 Monetary                100 2005 Virginia Home For Boys And Girls
       1992 Monetary                500 2005 Virginia Home For Boys And Girls
       1992 Individual                1 2003 Virginia Museum of Fine Arts
       1992 Individual              500      WHYY-TV
       1992 Monetary                  1 2002 Wake Forest University

22 rows selected.

SQL> 

SY.

Tags: Database

Similar Questions

  • OBIEE BI answers: measures bad aggregation at the top level of the hierarchy

    Hi all,
    I have the following problem. I hope to be clear in my English because it is somewhat complicated to explain.

    I did following:

    ID of drugs classified in quantity
    1 9
    2 4
    1 3
    2 2

    and drugs following table:

    Drug brand Id brand Description drug whose active ingredient Id drug whose active principle Description
    Aulin Nimesulide 1 1
    2 Asprina 2 Acetilsalicilico

    In AWM, I've defined a Dimension of drugs based on the following hierarchy: drug whose active ingredient (parent) - brand name of medication (sheet) mapped as Description:

    The active ingredient of drug = drug Active ingredient Id of my Table of drugs (pharmaceutical = Description of the active ingredient LONG DESCRIPTION attribute)
    Pharmaceutical brand Description = drug brand Id of my drugs Table (LONG DESCRIPTION = Description of drug brand attribute)

    Indeed, in my cube, I have traced pharmaceutical leaf-level brand Description = Id of the drug of my fact table. In AWM drugs Dimension is mapped as Sum aggregation operator

    If I select on answers drug whose active ingredient (parent of my hierarchy) and the quantity, in my view, after the result

    Description of the active ingredient drugs classified in quantity
    Acetilsalicilico 24
    Nimesulide 12

    indeed of the correct values

    Description of the active ingredient drugs classified in quantity
    Acetilsalicilico 12
    Nimesulide 6

    EXACTLY the double! But if I dig drug Description of the active ingredient Acetilsalicilico I can't see correctly:

    Drug whose active ingredient Description pharmaceutical brand classified in quantity Description
    Acetilsalicilico
    -12 Aspirina
    Total 12

    Aggregation of evil is only at the top level of the hierarchy. The aggregation on the lower level of the hierarchy is correct. Perhaps the answers also amount Total line? Why?

    I'm frustrated. I ask your help, please!

    Giancarlo

    OK your on 10G but the view of the cube and the obligation to limit the levels in the LTS in the RPD is valid in both.
    I think we found the problem,
    Go to each source logical table this logic table (x 2 in your case you have two levels) and on the content tab, window background ' use this "Clause Where" filter to limit the rows returned. »
    Open the expression builder, locate LEVEL_NAME according to your cube and limit accordingly, it is to say LEVEL_NAME = "BRAND_DESCRTIPION" for the aggregation BRAND_DESCRIPTION LTS and LEVEL_NAME = "XXXX" in detail, SFF, where XXXX is the name of level of hierarchy in your cube for details (leaves) records.

    Can you try that and let us know?
    Thank you
    Alastair

  • I did not purchase request how the amount is deducted from my account without my knowledge

    Hello

    1. I did not purchase request how the amount is deducted from my account without my knowledge. I ask you to return the amount to my account

    2. you download the free app and I have not purchased the app, I didn't purchase was deducted without my knowledge

    3. I ask you to bring the amount in my account and I will sue you to withdraw money from my account without my knowledge

    < re-titled by host >

    Maybe it's authorization is to identify yourself, the money will be in a few days.

    Read here: on the payment card's authorization in the iTunes Store - Apple Support

  • I type an e-mail; When I reached twenty lines, it won't let me nothing else in this e-mail type space... What can I do to increase the amount of text?

    Is it possible that I can increase the amount of text that is allowed when entering an email. I'm going to
    banging a long e-mail to someone and after 20 lines or more - no matter if I use spaces
    between the lines or not - even in the middle of a value - IT will appear all the words that I type...

    Sometimes, after he ceases to record what I type in an email; I can move on 8-10 lines and I can't
    type the new text that will record... but not all the time and when people read my mails, they do not realize
    the rest of my remarks in an e-mail message that are so far down the page...
    Help!
    Blessings, Judy

    Firefox send an e-mail, it's strictly a web browser.

    If you use Firefox to access your e-mail, you use "webmail". You must seek assistance from your service provider or a forum for this service.

    If your problem is with Mozilla Thunderbird, let know us and we can move this thread to the queue of Thunderbird. This issue is currently in the queue of Firefox to get answers.

  • How to reduce the amount of information in the box above the message text box

    When I opened an email there is a space above the text of the actual e-mail that contains a wealth of information and includes titles such as From, subject, Message ID, X-key etc. This area can be hidden from view?

    Sincere greetings,

    TREV

    You can reduce the amount of text illustrated by putting in

    Reviews | Headers of to normal. I think that yours is set on all the.

    http://www.Ramsden.org.UK/5_Lost_toolbars.html

    You can further reduce the size of the Panel itself with this add-on:

    https://addons.Mozilla.org/en-us/Thunderbird/addon/compactheader/

    http://www.Ramsden.org.UK/3_How_to_install_Add-ons_in_Thunderbird.html

  • How can I change the amount of emails display in ios9?

    How can I change the amount of emails display in ios9?

    jamesfromsherman wrote:

    How can I change the amount of emails display in ios9?

    The last iOS is no longer necessary for the former limits to be implemented since older versions of iOS where you would choose Show only recent 500, etc. You are now free to see your full Inbox. If you are using a POP account and see a bunch of messages that display as unread when you already read, you can access this mailbox on your iPhone, tap on edit and then Mark All > mark as read. Might also trash them if you wish.

  • The amount of space (memory) required for the good functioning of Firefox?

    The amount of memory required for the operation of Firefox? Trying to decide between IE and Firefox. Research in the new computer and need to think about which browser to use, and how much space it needs to work properly.

    You need no more than 40 MB for the operation of Firefox.

  • Please cancel the payment I made there is little time - 60-90 minutes, and/or credit my credit card for the amount I paid. It's more trouble than it is worth. I have

    Simply cancel the payment I made on my Visa for registration and download. It's all about confusion. I'm in no condition to continue playing with this situation. Just cancel the payment or my credit card for the amount paid. $35 + I'll just just another browser.

    Marie Heckel

    Looks like you've been scammed. Firefox is a free browser that does not require nor payment or registration. Never download from anywhere but the official site:

    Please report the offending on the following site:

    You will have to regularize the situation with the one who took your money, or failing that, with your bank or credit card company.

  • How can I reduce the amount stored?

    How can I reduce the amount stored?

    The amount is stored where? You must provide specific information about what it is you want to do.

    GB

  • Why web pages very slow to load regardless of the amount of content on the page?

    This problem happens almost all the time. I have the latest version of Firefox, but it happened for quite some time. Sometimes the pages load fast enough, but more often than otherwise, I do a right click on the tab to reload the tab seems not to matter the amount of content it is on a Web page or the number of tabs I have open.

     i have DISabled my norton security suite version 6.3.0.14 firewall and antivirus but it did not make any difference.  pages still loaded slowly
    

    There are several different solutions that various people have had success with:

    One is Flash 10.3 downgrade. [[Flash 11.3 crashes#w_solution-2-downgrade-to-flash-10-3|]] Solution Flash 10.3 2:Downgrade]]

    Another is reset Firefox: Firefox Refresh - reset the parameters and modules

    I would like to know if one of these help!

  • Satellite L30 - 101 videocard memory: how to change the amount of shared memory?

    Hello. I'm using Windows Vista and I have a problem with my VGA settings. There is no option to set the amount of memory on the part that is using my video card. In the BIOS, or the Catalyst Control Center. I can't fix same refresh rate of 70 Hz screen because the pilot is automated at 60 Hz settings without editing option. How can I change this? When I try to play call of Duty even the intro movies are skippy, even after installing the latest version of Direct X. The game is relatively good running, but I think on this configuration, it should work much better.
    Here are my specs:
    CPU: Intel Celeron M 1.5 Ghz
    Video: ATI Mobility Radeon Xpress 200M up to 256 MB
    RAM: 1.5 Ghz

    Hello

    If you want to learn a little more about the refresh rate of the screen and why he s a standard on screens TFT please check this post:
    http://forums.computers.Toshiba-Europe.com/forums/thread.jspa?threadID=19588&MessageID=71816

    It s a useful description.
    But generally, I agree with Abe. The 1.5 Ghz processor is enough to use normally. But if you want to play games like Call of Duty you will need a lot faster for laptop.
    Of course, this game run also on the unit you but you will not be able to play this game with a maximum return.

  • How can I see the amount of cycles of battery on the Satellite U200-181?

    I have Satellite U200-181, and I use it hard, each. I want to be ready replace my battery, when he has 400 cycles.
    How can I see the amount of cycles of battery on my laptop?

    You shouldn't see this. You will see that the battery capacity goes down and will be empty shortly after. No one says that you will be able to use the 400 battery cycles only. You may be lucky and the battery will be more long service life.

    My Tecra M1 is about 4 years old and still works with the original battery.

    Your question is quite unusual and I am really interested about new comments.

  • How to reduce the amount of storage to free up more space

    How to reduce the amount of storage to free up more space

    There are several things you could do.

    Save your iPad to iTunes on a computer or create an iCloud account, find out how much storage space you need for data and if you need to buy storage space monthly, to do. Then save your iPad to iCloud.

    HOWEVER the data backup on your iPad using WiFi or Bluetooth wireless, local devices such as portable hard drives or small flash memory drives designed for use with mobile devices, like the iPad.

    Remove the applications that you use is no longer. If you start to use them in the future, you can re-download them the iOS App Store.

    Thin out / remove the amount of music and movies you have on your iPad.

    If you make a backup of your iPad, you can thin out / delete all images stored in the iOS App Photos.

    Thin out / remove all books electronic, iBooks, eMagazines, and PDF documents, you have stored on your iPad. Magazines and e-books can be redownloaded at a later date.

  • HP Pavilion Dv7 Notebook PC: The amount of RAM is this laptop able to use? Also the quesiton to scan fingerprints

    Good so recently my computer has been doing slower and I thought that an upgrade of RAM could not wrong at all. If the amount of RAM would this laptop computer plug and what kind of RAM would be best? My processor is the Intel Core processor i5-2430 btw.

    Also, my fingerprint reader does more that my computer has been running for awhile but refonctionneront once I restart my computer. A way to solve this problem or is it just a little thing, I have to live with?

    Thanks in advance

    Hello

    Your computer is a HP Pavilion dv7-6179us , and it supports 16 GB of RAM max:

    http://support.HP.com/GB-en/document/c02996684

    Kind regards.

  • Use icloud for storing my photos will reduce the amount of space these pictures tak - up on my iphone?

    Use icloud for storing my photos will reduce the amount of space these photos take on my iphone? I guess the pictures would be automatically download on icloud but under settings, it tells me photos waiting to be downloaded, why?

    Yes, if you delete them from your device.

Maybe you are looking for

  • Search bar is pre-populated with the homepage

    When I change my homepage to google - the address bar comes always pre-populated with the 'https://www.google.com/?gws_rd=ssl' which means that as soon as I start typing it adds this url. I just want to have an own address with new tabs bar, so I can

  • Process can be configured to run after logout?

    We just bought a MAC Mini that we replace our computers on Windows Server with. We intend to expand that more and more current El Capitan and Apple server to file services away. The current problem is that we have installed Vmware Fusion 8 Pro and th

  • Detection of peak at the same time

    Hello I have two waves A and B with 10000 sampling point. Now, I want to find Max and Min waveform peak value has and correspond to what I want to know the respective value of the B wave. So end of thw Finally I have the Max value of A and this is th

  • Windows XP or Windows 7

    I have Dell Dimension E310 and I replaced the card mother, hard disk and cpu. I'm trying to find out what operating system to install. I had Windows XP on the old system, but I only have the CD more. Can I install Windows 7?

  • Cannot get sound on HDMI 5.1

    I just bought an Aspire E5 - 571 G-583R and I am trying to get a sound 5.1 from him. I connected the laptop HDMI to my home theater system that supports Dolby Digital and DTS, does not. I also tried my LG led - TV, which supports Dolby Digital, that