Recovering the year max for combination when the parameters are not exists

I try to query a table that maintains cumulative information by calendar_year and calendar_period. The problem I encounter is that if I want to ask the total of the transaction for a combination of accounting from a certain calendar_period and calendar_year, I need get the max calendar_year and calendar_period for the previous year or period for the current_year and max calendar_year by combination of accounting (Fund, org prog (, acct) which falls outside the parameters in my where clause, which for this example would be calendar_year = '15' and calendar_period = '03'. For most of all sense I'll post and excerpt from my table.

create table

CREATE TABLE "MAXTABLE"
   (    "CALENDAR_YEAR" NUMBER,
    "CALENDAR_PERIOD" NUMBER,
    "AMOUNT" NUMBER,
    "FUND" VARCHAR2(20 BYTE),
    "ACCOUNT" VARCHAR2(20 BYTE),
    "ORG" VARCHAR2(20 BYTE),
    "PROG" VARCHAR2(20 BYTE)
   )






values in the table.

REM INSERTING into MAXTABLE
SET DEFINE OFF;
Insert into MAXTABLE (CALENDAR_YEAR,CALENDAR_PERIOD,AMOUNT,FUND,ACCOUNT,ORG,PROG) values (15,2,25,'202118','2071','3662','121');
Insert into MAXTABLE (CALENDAR_YEAR,CALENDAR_PERIOD,AMOUNT,FUND,ACCOUNT,ORG,PROG) values (15,3,150,'202118','2070','3662','121');
Insert into MAXTABLE (CALENDAR_YEAR,CALENDAR_PERIOD,AMOUNT,FUND,ACCOUNT,ORG,PROG) values (14,12,50,'202118','2040','3662','121');
Insert into MAXTABLE (CALENDAR_YEAR,CALENDAR_PERIOD,AMOUNT,FUND,ACCOUNT,ORG,PROG) values (14,3,100,'202118','2070','3662','121');
Insert into MAXTABLE (CALENDAR_YEAR,CALENDAR_PERIOD,AMOUNT,FUND,ACCOUNT,ORG,PROG) values (13,14,50,'202118','2010','3662','121');






so now I want to run a query which would show me the total amounts by combination of accounting (Fund, account, org, prog) and I'd like to get it from calendar_year '15' and calendar_period ' 03 ".

I need essentially back on the period and the year previous years courses and get the max (calendar_year) and the max (calendar_period) for the Fund, account, org, combination of prog that is not in the calendar_year '15' and calendar_period ' 03 "

so the results would look something like below. Also the max_period and max_year could be in the same calendar year that I ask for this combination of accounting, an example of this is the 2070 account in the result below.

I would like to run a query similar to this one

SELECT
   CALENDAR_YEAR,
  CALENDAR_PERIOD,
  AMOUNT,
  FUND,
  ACCOUNT,
  ORG,
  PROG
FROM MAXTABLE
WHERE CALENDAR_PERIOD = '03'
AND CALENDAR_YEAR = '15';






but it would give me only the amounts on the table which exist for this year and the period. I also need to get the max calendar_year and max_calendar_period before calendar_period 03 and calendar_year 15 and add those to my request.

.expected output:

Calendar_Year calendar_period amount Fund account org PROG
1522520211820713662121
15315020211820703662121
14125020211820403662121
13145020211820103662121

noticed that I'm not getting the $100 for account 2070 calendar_year question 14 and calendar_period ' 03 ". This point has already had a calendar_year max 15 and period 2 so I exclude it, since is less than 15 calendar_year but it is also a lot already this combination of accounting.

Hope it makes sense.

Sorry, I did not single-digit into account correctly.  Two years and by the need to be wrapped with to_char as:

TO_CHAR (yr, 'fm00') | TO_CHAR (per, 'fm00')<=>

John

Tags: Database

Similar Questions

  • The parameters are not sync between CC AI and AI CC 2014

    I can't get AI AI CC 2014 CC sync settings. I am able to sync settings HAVE CC and supposedly they are available in the cloud, but when I open AI CC 2014 workspaces and keyboard shortcuts are not available for me to choose. Having the same problem in CC ID and ID CC 2014 as well. I was finally able to get PS CC 2014 to load my settings, but I'm not entirely sure why those decided to appear. Anyone else having this problem and have a solution to fix?

    Stuart, l3acon,

    It has been in other threads here. CC 2014/DC18 works as a new version.

    import parameters in cc 2014

  • I am running Windows 7 and noticed that Windows updates did not work. The parameters are defined for the update every day. When I went to update manually returned an error WindowsUpdate_80070017. MSFT site was no help. Any recommendations?

    I am running Windows 7 and noticed that Windows updates did not work. The parameters are defined for the update every day. When I went to update manually returned an error WindowsUpdate_80070017.  MSFT site was no help. Any recommendations?

    Since neither updates Jan - 10 have installed, I'm going to hand you Support MS in the hope that they can resolve the problem. See below.

    That being said, is an interpretation of the 80070017 - cyclic redundancy check error "a device attached to the system does not work," which suggests that a hardware problem might be the cause of the error (although I must say that it is a very low possibility in this case).

    Good luck!

    =======================

    Visit the Microsoft Solution Center and antivirus security for resources and tools to keep your PC safe and healthy. If you have problems with the installation of the update itself, visit the Microsoft Update Support for resources and tools to keep your PC updated with the latest updates.

    ~ Robear Dyer (PA Bear) ~ MS MVP (that is to say, mail, security, Windows & Update Services) since 2002 ~ WARNING: MS MVPs represent or work for Microsoft

  • I imported the pic of a flash drive files in Movie Maker. When I return to my project overnight the pictures do not exist.

    I work in Windows Movie Maker.  I imported the pic of a flash drive files.  When I return to my project overnight the pictures do not exist.   They don't last load because the 'not found' files, mysteriously images loaded back up everything.  I have no idea of what I did, but they found themselves back much to my relief however, today, I'm not so lucky.    Tonight, it's the same thing, but the only way I can get the pictures if I find the missing photo 1 by 1 by right click and search for my flash drive.  I have my flash drive in my computer when I started working on my project again. I put a dvd set for my nursery and I have many many photos and I can't click on each of them.  Please give me some useful advice soon so I'm not crazy!  School is out next week! I know that there must be an easy fix.

    Thank you very much :)

    Dana

    original title: Windows Movie Maker

    What source files have been moved, deleted,
    renamed or are otherwise inaccessible... it
    will be red Xs in the Movie Maker Collection
    Pane. And you're right... If files are always
    available path may be restored with
    a right click / Browse.

    Given that the Movie Maker project file does not work
    Archive copies of your original source files...
    It would be preferable that you copied your files to a
    folder on your hard drive and import them into movie
    Machine from here.

  • When I edit a .wav file (noise reduction to remove the background hiss) and save them, the changes are not saved.

    I just installed hearing and have edited a few audio voiceover to remove the background hiss.  When I save the changes and reopen the file, the hiss is back.  The changes are not saved.  Why is this happening?  How to record the sound of the effects of reduction in my .wav file?

    [Ask in the correct forum allows... Left generic Cloud/Setup forum for forum specific program... MOD]

    shionak wrote:

    I capture the background hissing noise footprint > click apply > click on select, then click on apply again.

    These steps are not quite correct. You have two choices; either highlight a part of the background noise and use SHIFT + P, which captures your selection as a basis for NR or, open the Panel NR and use "Capture noise Print" from there, after making a selection first. After doing this, click on "select an entire file. What you definitely have to do is to use 'apply' at this point, and when use you it, just use it once.

    When you capture using printed, the Preview 'play' button inside the plugin to check the settings and then stop it. When you are satisfied of what he done, then click on 'Apply' - but once. This will apply for all of your noise reduction. As long as you do not use "undo" at any time, the version Number will be be recorded on the original, or if you use "save under", then the original will be left alone, and a new noise-reduced version will be saved.

  • VMware Player tells me to 'host reserved RAM', but the option does not exist.  Is there a command for vmx to this file?

    I am running VMware Player on a host Ubuntu 14.04, Win 7 pro x 64 comments.  When I start the client OS VMWare gives me this warning

    Vmware Player Warning.png

    So I want to allow the use of the "reserved host RAM" option instead of playing with the pagefile, but setting told me to doesn't seem to exist in VMware Player

    vmware player mem settings.png

    Is there something I can add to the VMX file to enable this option?

    Porto Richardson wrote: this setting for VMware Player is found in the file config.ini to the player %allusersprofile%/VMware/VMware

    The OP said "I'm under VMware Player on a Ubuntu 14.04 host" so the file name and path you mentioned is not applicable.

    @LukeJS host on a Ubuntu (Linux) from the file name won't get the .ini extension and will be simply called the config and will be parked at/etc/vmware /.  So with the machine virtual shutdown is not suspended and VMware Player closed then a Terminal used the following command.

    sudo nano/etc/vmware/config

    Then add the following line.

    prefvmx.minVmMemPct = "100".

    It is essentially the same parameter that gets the value of the UI of VMware Workstation preferences for submission in response to the message that despite the instructions contained in the message does not exist in the VMware Player preferences user interface.

  • How to find vCenter virtual cluster large when the services are not running?

    Does anyone have advice for locating vCenter in a cluster, when his services are not running?

    For example, I have to restart vCenter and its network is having issues.  I need to go to the host ESX (i) is on and open the console to get to the virtual machine.  But to find that host is on can sometimes take a long time, because I have to log in to each HOST and see if it is the host where vCenter.

    Does anyone have any advice or suggestions to make this process easier?  It is not so important, but just curious to know what others might suggest.

    Thank you.

    I used PowerCLI and

    to connect-viserver esx1, esx2, esx3

    connect to all the ESX(I) hosts and then run

    Get - vm vCenterServerName | Select the name, the host

  • a key for the table does not exist in the table

    Hi guys,.

    I imported several tables of physical layer in the administration tool. So, I want to do new foreign key between tables join in the physical schema.
    Required fields for posting a link between these tables are set up. When I press the ok button, an error message is displayed:
    "a key corresponding to the table does not exist in the table blablabla. You want to create a? »

    In fact, what is this error? I don't have all the idea about it. The number of the type of the fields is the same, the names are also the same. I think that he should not have problems to make the new foreign key. But why is it happening?

    Thank you

    Hello

    It is the primary key of the first table. You might not have set this column as the primary key of this table at the level of the db.

    Thank you
    Imtiaz.

  • For the second time in two months, all my messages in the Inbox are not there. Only the SUBJECT and the FROM is left. Tried to 'fix this folder' and lost ALL

    For the second time in two months, all my messages in the Inbox are not there. Only the SUBJECT and the FROM is left.

    Tried to 'fix this folder' and ALL - lost ALL the Inbox.

    The file is still there and works well...

    How can I stop it and what are the causes?

    Thank you all, Gabe

    If you have the file somewhere on your hard drive, export and import tools it will be important back to Thunderbird.

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

    Instructions http://chrisramsden.vfast.co.uk/3_How_to_install_Add-ons_in_Thunderbird.html

  • I get emails with pictures and when I send them to others. they open them but the images are not displayed. The photos are there when I send them. Thank you

    I get emails with pictures and when I send them to others. they open
    their place but the images are not displayed. The photos are there when I send a
    them. Thank you

    Make sure that your security software (antivirus) is not blocking attachments.

  • I am not able to download apps for my iPhone on the App Store. He just 'waiting '. But never starts the download. I tried with wifi and mobile data. The two are not download apps

    I am not able to download apps for my iPhone on the App Store. He just 'waiting '. But never starts the download. I tried with wifi and mobile data. The two are not downloading the applications Can u find out what's wrong? I use iPhone 5s

    I had the same problem. At the same time hold the screen lock button and the home button until your iPhone restarts. That solved the problem for me.

  • When I send emails containing photos, which were reported by the recipients that the photos are not coming.

    When I transfer emails containing images, it has been reprted bythe recipients that the pictures are not coming. Explain please.

    original title: transfer of emails

    What email program are you using?

  • Why the Secure areas not at my disposal when I manage my site?

    I just rebuilt my site in Muse and transferred to the Cat Business. I tried to add a protected area, but the option does not exist. Is it a thing of Muse and admin thing?Screen Shot 2015-11-07 at 8.56.56 AM.png

    Hey, I suggest to contact support if the problem persists. In addition, mention the URL of the site and the user name, that you connect to when the safe areas is not displayed.

    Kind regards

    Mihai

  • Looking for some practice files for video in line/book of "Adobe Photoshop CS5 Extended: Essentials. I use the tutorial via membership in Safari book online and the files are not available on Safari.  Do you know where I can get the files?

    Looking for some practice files for video in line/book of "Adobe Photoshop CS5 Extended: Essentials. I use the tutorial via membership in Safari book online and the files are not available on Safari.  Do you know where I can get the files?

    Looks like the manufacturer was "Total Training. I can't find the title to Adobe.com

    http://totaltraining.com/store/Photoshop-CS5-extended-Essentials/

  • I had the teacher edition, but never received an email with the details of the product, etc. and the products are not installed (they ask for product key, etc)... What are you doing?

    I had the teacher edition, but never received an email with the details of the product, etc. and the products are not installed (they ask for product key, etc)... What are you doing?

    Hello

    did you purchase your product of these companies like Amazon? If Yes, this isn't a serial number, only a code with which you can request a serial number from Adobe. Please take a look at http://helpx.adobe.com/x-productkb/global/find-serial-number.html. (Start here: How did you purchase your product?)

    The next part, so I don't see at the very least, ceased to exist on my Adobe website, everything happens in the link above. I leave as an info yet, he could still fit for you. For this purpose, please click your way through your Adobe Store and find the button "get serial number". Fill in the form and after awhile, you will get the real serial number.

    Hans-Günter

Maybe you are looking for

  • P 259 ng: Pavilion P 259 ng with win 7

  • Model SolidWorks coupling question in 3D Picture control

    Hello I followed example LQR and linear inverted pendulum... .or we can import Solidworks model in Labview and have our own control... SCARA, I did and I am able to access each part... but I have still a few mating issues with individual part... Plea

  • Can I print on canvas of the HP Officejet 6500 printer?

    I want to print on canvas paper. I don't know if my printer model (it's a Scanner printer Officejet 6500 Fax) is compatible.In Print Options, I don't have the option of canvas. I looked for HP paper canvas online and is that big rolls that are too wi

  • Windows 7 not genuine after 1 month of use

    I bought my computer in a T-shirt shop that had improved their equipment.  It has Windows 7 Ultimate on it.  It has worked well for more than a month until that one day he began to say that the copy was not authentic.  Here are the results of the dia

  • Error 1502

    While trying to build a previously exe version I get the following error. 1502 error to AB_Source_VI.lvclass:Close_Reference.vi-> AB_Build.lvclassave.vi-> AB_Build.lvclass:Copy_Files.vi-> AB_Application.lvclass:Copy_Files.vi-> AB_EXE.lvclass:Copy_Fil