the LAST_VALUE function and forecasts

Dear gurus,

I need to return a result set with the last value from the last date of my contracts, table of projects; that later, I'll have to use this game to project values for the months remaining of my earnings forecasts.

I don't seem to be getting anywhere, I need to take the last date, the pair value per project / contract and project.

I only went as far as the first part, which is to extract the last date, value; will also need assistance for the second part, which must take this bring and project.

Here we go:

my table

Contrato projeto, data, valor

C001P1APRIL 1, 1510
C001P1APRIL 1, 1510
C001P11 MAY 1515
C001P21 MAY 1519
C001P21 JUNE 1521
C002P1JULY 1, 1519
C002P21 AUGUST 1519

my query

Select CONTRATO, PROJETO, KITCHEN,

LAST_VALUE ("PERIODO" IGNORE NULLS) OVER (PARTITION BY contrato, projeto, Transcanada, periodo ORDER BY contrato, projeto, FCST RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) LAST_DATE

de)

Select CONTRATO, PROJETO, periodo,

LAST_VALUE ("VALOR" IGNORE NULLS) ON FCST (PARTITION BY projeto, periodo, valor ORDER BY PERIODO, contrato, contrato, projeto VARY without LIMIT PREVIOUS of UNBOUNDED FOLLOWING)

OF 'HYP_STAGE '. "" INVENT_TABLE_FCST ".

) ORDER OF CONTRATO, PROJETO, PERIOD.

My result set, repeat the values for the month, only need one value per month;

C001P110APRIL 1, 15
C001P110APRIL 1, 15
C001P1151 MAY 15
C001P2191 MAY 15
C001P2211 JUNE 15
C002P119JULY 1, 15
C002P2191 AUGUST 15

Thank you very much!

Forecasts up to 2015-12-31

SELECT

Contrato

projeto

, to_char (pmonth, ' MONTH YYYY ',' NLS_DATE_LANGUAGE = ENGLISH ') month

valor v

DE)

Select

Contrato, projeto

trunc (max (period), "MM") pmonth

, max (valor) valor of Dungeon (dense_rank last order by period)

of INVENT_TABLE_FCST

Contrato group, projeto

)

model

partition of (contrato, projeto)

dimension (r 0)

measures (v valor, pmonth)

iterate (1e6) rules until (add_months(pmonth[0],iteration_number) > = DATE '' 2015-12-31))

pmonth [iteration_number] = ADD_MONTHS(pmonth[0],iteration_number)

v [iteration_number] = v [0]

)

order of contrato, projeto, pmonth

CONTRATO PROJETO MONTHS VALOR

'C001' 'P1' 'MAY 2015', '15 '.

'C001' 'P1' 'JUNE 2015', '15 '.

'C001' 'P1' 'JULY 2015', '15 '.

'C001' 'P1' 'AUGUST 2015', '15 '.

'C001' 'P1' 'SEPTEMBER 2015', '15 '.

'C001' 'P1' 'OCTOBER 2015', '15 '.

'C001' 'P1' 'NOVEMBER 2015', '15 '.

'C001' 'P1' 'DECEMBER 2015', '15 '.

'C001' 'P1' 'JANUARY 2016"'15 '.

'C001' 'P2' 'JUNE 2015' "21".

'C001' 'P2' 'JULY 2015' "21".

'C001' 'P2' 'AUGUST 2015' "21".

'C001' 'P2' 'SEPTEMBER 2015' "21".

'C001' 'P2' 'OCTOBER 2015' "21".

'C001' 'P2' 'NOVEMBER 2015' "21".

'C001' 'P2' 'DECEMBER 2015' "21".

'C001' 'P2' 'JANUARY 2016"'21 '.

"C002' 'P1' 'JULY 2015'"19. "

"C002' 'P1' 'AUGUST 2015'"19. "

"C002' 'P1' 'SEPTEMBER 2015'"19. "

"C002' 'P1' 'OCTOBER 2015'"19. "

"C002' 'P1' 'NOVEMBER 2015'"19. "

"C002' 'P1' 'DECEMBER 2015'"19. "

"C002" "P1" "JANUARY 2016", "19".

"C002' 'P2' 'AUGUST 2015'"19. "

"C002" "P2" 'SEPTEMBER 2015' "19."

"C002' 'P2' 'OCTOBER 2015'"19. "

"C002' 'P2' 'NOVEMBER 2015'"19. "

"C002' 'P2' 'DECEMBER 2015'"19. "

"C002" "P2" "JANUARY 2016", "19".

Tags: Database

Similar Questions

  • Hi, I'm developing a simple mobile app in DW CC 2015 using JQuery Mobile. LIKE I need the list view with description of the product, functionality and image, I would like to connect with database instead of "writing" all the tables in the bearings inside

    Hi, I'm developing a simple mobile app in DW CC 2015 using JQuery Mobile. LIKE I need the list view with description of the product, functionality and image, I would like to connect with database instead of "writing" all the tables in the bearings inside the Jquery page. In the future I would also be able to add, to remove the DB records. Any help, tutorial... Thanks TG

    I would like to connect with the database instead of "writing" all the tables in the bearings inside the Jquery page

    This is usually done with a CMS (content management system). There are commercial products CMS like WordPress, Joomla and perch. You create one or several layouts and then create pages of these page layouts using the CMS. In this way, it is possible to have hundreds of pages, each with unique content, but a page layout that can be managed in a place of sharing.

    CMSs on shelf don't require programming skills. Otherwise, some of us write our own CMS with custom functions, but this requires back-end, as with PHP programming.

  • I use the random function and he know instructions 'case' must end with a ':' but it is!

    I use the random function and he know instructions 'case' must end with a ':' but it is! I put

    case 10000 timer += 2; popupName._visible = true; :

    then I put

    case of 10000 {timer += 2; popupName._visible = true ;}:}

    but he still know it.

    What I am doing wrong?

    First of all, whenever you have more than three similar lines, you should probably refactor something.  Especially when you have 10,000 lines. This should have sounded the alarm, but I guess you are new to this.

    Second, when you have such a long code, paste everything here. Please, I beg you. It's a pain to navigate the thread.

    And here's what I * think * you really want:

    If (random (10001) == 10000) {}

    timer += 2;

    popupName._visible = true;

    }

    It simply means: "take a random number between 0 and 10001 (exclusive). If this number is 10,000, do something. If not, ignore this code block. »

  • Any difference between the separate function and aggregation in sql query cost?

    Hello
    I've run many models sql stmts - such as:
    one) using a single table
    (b) using the two tables, using simple joins or outer joins

    but I didn't notice a difference in sql stmts in cost and implementation plan...
    In any case, my colleague insists on only using the aggregate function is less expensive compared to
    separate... (something I've not confirmed, that is why I believe that they are exactly the same...)

    For the situation described above under 1 sql... We could for example use
    select distinct deptno
    from emp
    select count(*), deptno
    from emp
    group by deptno
    select distinct owner, object_type from all_objects
    select count(*), owner, object_type from all_objects
    group by owner, object_type
    Have you ever found no difference between the two...?

    Note: I use Ora DB 10g v2.

    Thank you
    SIM

    Alexandre Gelin says:
    function separate and aggregation are for different uses and can give the same result, but if you use the aggregate function to get the separate records, it will be expensive...

    really? I find them almost identical to 11g. Actually GROUP BY is almost always more fast for me in the old days.

    article about this askTom Re: any difference between the separate function and aggregation in sql query cost?
    This applies mainly to the older oracle versions http://www.oracle.com/technology/products/rdb/pdf/distinct_derivedtables_groupby_sort_tech_article.pdf

  • Problems with the sound function and scrolling on the touchpad on my Satellite A500/026

    Hello

    I just brought a new laptop A500/026 and when I play music from my ipod I get a little static pop sound at regular intervals during the song... this happens on all my music. I accidentally scroll horizontally through my touhpad and my screen minimizes or maximizes. I try to find how I did it, but can never seem to return to its normal state. There is obviously some sort of function here, can someone help me with it? I installed the x 64 bit version of windows 7.

    Thank you

    Eddie

    Hello

    The touchpad settings are placed in Control Panel-> mouse
    You can find the additional tab which would be you can access touchpad properties.

    As I know the touchpad properties contains many different options that allows you to configure the scrolling function, to activate and assign different actions to the touchpad corners, etc.

    Check it!

  • Bug with the aggregate function and no group

    When I run the following query:
    with the_table as
    (
      select 1 as id, 100 as cost from dual
      union all select 2 as id, 200 as cost from dual
      union all select 3 as id, 300 as cost from dual
      union all select 4 as id, 400 as cost from dual
      union all select 5 as id, 500 as cost from dual
    )
    select id, cost
    from
    (
      select id, cost
      from the_table
      --
      union all
      --
      select 0 as id, sum(cost) as cost
      from the_table
      where 0 = 1
      -- group by 1
    )
    order by id;
    I get this result:
    ID    COST
    --  ------
     0  <null>     
     1     100
     2     200
     3     300
     4     400
     5     500
    However, when I "uncomment" the line "Group 1", the query works as expected (without the id = rank 0).

    This occurs even when "the_table" is an array.

    Someone else comes through this (and if so, how long is a problem)?

    The database is 11.2.0.2.0 64-bit.

    EDIT: It also happens without a Union - the following returns a single line (with null 0 and cost of id) without the Group By and no line with her:
    select id, cost
    from
    (
      select 0 as id, sum(cost) as cost
      from 
      (
        select 1 as id, 100 as cost from dual
        union all select 2 as id, 200 as cost from dual
        union all select 3 as id, 300 as cost from dual
        union all select 4 as id, 400 as cost from dual
        union all select 5 as id, 500 as cost from dual
      )
      where 0 = 1
      -- group by 1
    )
    order by id
    Edited by: Donbot February 15, 2012 10:29

    Donbot wrote:
    Someone else comes through this (and if so, how long is a problem)?

    The database is 11.2.0.2.0 64-bit.

    This is a documented behavior.

    http://docs.Oracle.com/CD/E11882_01/server.112/e26088/functions003.htm#SQLRF20035

    "
    All except COUNT (*) GROUPING and GROUPING_ID aggregate functions ignore NULL values. You can use the NVL function in the argument of an aggregation function to substitute a value for a null value. COUNTY and REGR_COUNT never return null, but return a number or zero. For all remaining functions of aggregation, * if the DataSet contains no line, * or if it contains only the rows with NULL values as arguments to the aggregate function, * then the function returns null.*
    "

  • limit the number of values in the listagg function and create several games

    Hi all

    I have a requirement where I would like to group one of the fields in a field based on the number of records. Lets say if we have an employee with multiple CODEZONE. Please see the example below. I want concatenation of each 10 EMPNO records into one. If she has more than 10 records for a given EMPNO, it should show in the form of another record.
    For example:
    EMPNO CODEZONE
    A111 AL
    A111 AK
    A111 AZ
    A111 AR
    A111 CA
    A111 CO
    A111 CT
    TO A111
    A111 DC
    A111 FL
    A111 GA
    A111 HI
    B222 AL
    B222 AK
    B222 AZ
    B222 AI
    B222 KS
    B222 KY
    THE B222
    B222 ME
    B222 MD
    MY B222
    B222 MI
    B222 CA
    B222 CO
    B222 CT
    B222 OF

    Result set:
    EMPNO CODEZONE
    A111 AL | AK | AZ | AR | CA | CO | CT | OF | DC | FL
    A111 GA | HI
    B222 AL | AK | AZ | AI | KS |     KY | THE | ME | MD | MY
    B222 MI | CA | CO | CT | OF

    The above example can have any number of area CODE for a given EMPNO, the end result should show only a maximum of 10 codes for an EMPNO in each record. If she has more than 10 CODEZONE, it should show as another record. Please provide me with a generic statement to solve this problem. I was not able to control by setting the limit on records for an EMPNO gave to the LISTAGG function. Any ideas are much appreciated.

    Thank you

    1008754 wrote:
    Hi all

    I have a requirement where I would like to group one of the fields in a field based on the number of records. Lets say if we have an employee with multiple CODEZONE. Please see the example below. I want concatenation of each 10 EMPNO records into one. If she has more than 10 records for a given EMPNO, it should show in the form of another record.
    For example:
    EMPNO CODEZONE
    A111 AL
    A111 AK
    A111 AZ
    A111 AR
    A111 CA
    A111 CO
    A111 CT
    TO A111
    A111 DC
    A111 FL
    A111 GA
    A111 HI
    B222 AL
    B222 AK
    B222 AZ
    B222 AI
    B222 KS
    B222 KY
    THE B222
    B222 ME
    B222 MD
    MY B222
    B222 MI
    B222 CA
    B222 CO
    B222 CT
    B222 OF

    Result set:
    EMPNO CODEZONE
    A111 AL | AK | AZ | AR | CA | CO | CT | OF | DC | FL
    A111 GA | HI
    B222 AL | AK | AZ | AI | KS |     KY | THE | ME | MD | MY
    B222 MI | CA | CO | CT | OF

    The above example can have any number of area CODE for a given EMPNO, the end result should show only a maximum of 10 codes for an EMPNO in each record. If she has more than 10 CODEZONE, it should show as another record. Please provide me with a generic statement to solve this problem. I was not able to control by setting the limit on records for an EMPNO gave to the LISTAGG function. Any ideas are much appreciated.

    Thank you

    ME_XE?with data (empno, areacode) as
      2  (
      3     select 'A111', 'AL' from dual union all
      4     select 'A111', 'AK' from dual union all
      5     select 'A111', 'AZ' from dual union all
      6     select 'A111', 'AR' from dual union all
      7     select 'A111', 'CA' from dual union all
      8     select 'A111', 'CO' from dual union all
      9     select 'A111', 'CT' from dual union all
     10     select 'A111', 'DE' from dual union all
     11     select 'A111', 'DC' from dual union all
     12     select 'A111', 'FL' from dual union all
     13     select 'A111', 'GA' from dual union all
     14     select 'A111', 'HI' from dual union all
     15     select 'B222', 'AL' from dual union all
     16     select 'B222', 'AK' from dual union all
     17     select 'B222', 'AZ' from dual union all
     18     select 'B222', 'IA' from dual union all
     19     select 'B222', 'KS' from dual union all
     20     select 'B222', 'KY' from dual union all
     21     select 'B222', 'LA' from dual union all
     22     select 'B222', 'ME' from dual union all
     23     select 'B222', 'MD' from dual union all
     24     select 'B222', 'MA' from dual union all
     25     select 'B222', 'MI' from dual union all
     26     select 'B222', 'CA' from dual union all
     27     select 'B222', 'CO' from dual union all
     28     select 'B222', 'CT' from dual union all
     29     select 'B222', 'DE' from dual
     30  )
     31  select
     32     empno, listagg(areacode, ',') within group (order by emp_grp)   as emp_list
     33  from
     34  (
     35     select
     36             ceil(row_number() over (partition by empno order by areacode) / 10) as emp_grp,
     37             empno,
     38             areacode
     39     from data
     40  )
     41  group by empno, emp_grp;
    
    EMPNO                          EMP_LIST
    ------------------------------ ------------------------------
    A111                           AK,AL,AR,AZ,CA,CO,CT,DC,DE,FL
    A111                           GA,HI
    B222                           AK,AL,AZ,CA,CO,CT,DE,IA,KS,KY
    B222                           LA,MA,MD,ME,MI
    
    4 rows selected.
    
    Elapsed: 00:00:00.05
    ME_XE?
    

    In the future, it would be nice if you could provide baseline data.

    See you soon,.

  • My mouse wheel stopped working all of a sudden. All the other functions and buttons work correctly. Help?

    I have a wireless microsoft 5000 mouse

    [Moved from comments]

    Hello

    1. don't you make changes to the computer before this problem?

    2. what security software is installed?

    3. what operating system is installed?

    Let us try these methods.

    Method 1.

    We can refer to this article and check if that helps.

    Mouse, touchpad and keyboard under Windows problems: http://Windows.Microsoft.com/en-us/Windows/help/Mouse-touchpad-and-keyboard-problems-in-Windows

    Method 2.

    We can refer to this article and check if that helps.

    Support for Microsoft mouse, keyboards, LifeChat, LifeCam & more: http://support.microsoft.com/ph/7746#tab1

    How to contact Microsoft if you have questions about your hardware device: http://www.microsoft.com/hardware/en-us/support/contact-us

    Let us know if you need assistance with any windows problem. We will be happy to help you.

  • The ABS function and the sum at a time

    <? If: sum (ARCH_AMT)! = '0' ? >

    We used above condition in the model to restrict the data to date, but we were faced with a new problem when ARCH_AMT is to have several lines with the same amount but + ve and ve - that is to say 500, -500, is the sum and do not return data given that the sum would be zero.

    We do ABS (ARCH_AMT) before making the sum that the SUM will be thousand and data will be collected.

    Please suggest how can we have ABS and the sum at a time

    I tried

    <? If: sum (ABS (ARCH_AMT))! = '0' ? > and also choose the conditions and it does not work.

    Thanks in advance.

    Kind regards
    Mahi

    Published by: mahi4luck on March 28, 2012 02:33

    store ABS (ARCH_AMT) in a variable and use this variable in a total cumulative

    example:
    Suppose I have a structure xml like this:



    -500


    500





    Total:

  • I used the inverse function for a palindrome bulk pl/Sql program, but it is said to declare the inverse function and my code is below! Please suggest me some friends of ideas and thanks in advance

    declare

    i_var varchar2 (30): = '& enter_string';

    Vout varchar2 (20);

    Start

    :=Lower(Reverse(i_var)) Vout;

    If lower (i_var) = vout can

    dbms_output.put_line ('this is a palindrome');

    on the other

    dbms_output.put_line ('this is not a palindrome');

    end if;

    end;

    I agree completely

    SQL > declare

    2 i_var varchar2 (30): = "& enter_string;

    3 vout varchar2 (20);

    4 start

    5 Select lower (reverse (i_var))

    6 in vout

    7 double;

    8 lower (i_var) = vout

    9. can

    10 dbms_output.put_line (i_var |) 'is a palindrome');

    11 other

    12 dbms_output.put_line (i_var |) (' ' is not a palindrome ");

    13 end if;

    14 end;

    15.

    Enter the value of enter_string: Bolton

    2 old: i_var varchar2 (30): = "& enter_string;

    2 new: i_var varchar2 (30): = 'Bolton ';

    Bolton is not a palindrome

    PL/SQL procedure successfully completed.

  • analytical function and the aggregate function

    What are the analytical function and the aggregate function. What is the difference between them?

    Hello

    Analytic Functions : -.

    Analytical functions calculate a value of aggregation based on a group of lines. They differ from aggregate functions because they return several rows for each group. The Group of rows is called a window and is defined by the analytic_clause. For each line, a sliding window of lines is defined. The window determines the range of lines used for the calculations for the current line. Window sizes can be based on a physical number of rows or a logic as the time interval.
    Analytical functions are the last set of operations performed in a query with the exception of the last ORDER BY clause. Every joint and every WHERE, GROUP BY and HAVING clauses are met before the analytical functions are handled. As a result, analytic functions can only appear in the select list or the ORDER BY clause.
    Analytical functions are commonly used to calculate cumulative aggregates, moving, centered and considered.

    Aggregate functions : -.

    Aggregate functions return a line of single result based on the groups of lines, rather than on the unique lines. Aggregate functions can appear in selection lists, as well as in the HAVING and ORDER BY clauses. They are commonly used with the GROUP BY clause in a SELECT statement, where Oracle Database splits the rows in a table when asked or seen in groups. In a query that contains a GROUP BY clause, the select list items can be aggregation functions, GROUP BY constant expressions or expressions involving one of them. Oracle applies the functions of aggregation for each group of rows and returns a single result for each group line.
    If you omit the GROUP BY clause, Oracle then applies any aggregate functions in the select list for all rows in the table queried or the view. You use aggregate functions in the HAVING clause to eliminate groups of the output based on the results of aggregate functions, rather than the values of the individual lines of the queried table or view.

    Let me know if you feel any problem understanding.
    Thank you.

    Published by: varun4dba on January 27, 2011 15:32

  • Z10 blackBerry a way to disable the bluetooth handset and use activate streaming audio only?

    I use bluetooth in my car to make or receive phone calls and it only allows you to stream Pandora.  On my previous BBs, I was able to disable the handset function and just use streaming, but I'm not find similar options on the Z10.  Does anyone know how to do this? Right now I just turn off my stereo when I receive a call, but this isn't a good solution.  Thanks for any comments.

    Hello oumiahamada and welcome to the community of BlackBerry Support Forums.

    Thank you for your question about Bluetooth.

    The Z10 BlackBerry doesn't have the option to edit what services are allowed with a Bluetooth connection.

    Depending on your vehicle, you will need to access your Bluetooth set up or the settings in the dashboard of your car to control what features are Bluetooth-enabled.

    If you don't know how to access these settings, contact your dealer or see your owner's manual.

    See you soon!

  • Click on the button conditional and alert when the condition is not met

    Hello

    I have a problem with the click of a button; in my form when the user clicks on a button I have to run the True action only if an element has the value; otherwise I would show an alert message like "enter value < element >...". ».

    It seems a simple problem, I tried to insert the condition "Is not null" and warning that the action of false, but it does not work.

    Who is the Apex way to solve?

    Thanks in advance.

    Cry

    1. replace the button URL type

    Code - javascript:validate();

    2. create a javascript function in the page function and declaration of global variables

    function validate()

    {

    If ($v ('YOUR_ITEM_NAME') == ")

    Alert ('XYZ');

    on the other

    Apex. Submit ('BUTTON_NAME');

    }

  • PS elements 11 cannot use the text function. Error message could not initialize the text.

    When I try to use the text function the letters do not appear. Text feature appears frozen. Get the error message - unable to initialize the text.

    Recently PSE11 uninstalled and reinstalled. Downloaded 2 Google font. Was able to use the text function with Google fonts with no problems. Two days later, attempted to work with the text function and the typed letters appear on the screen/layer. Tried to add the text with fonts pre-installed PS - still once, no text appeared. Impossible to set up a text box. How can I fix it? Thank you

    Suggest that you reset the text tool, that only he can fix.

    I believe in PSEv.11, there is a small arrow, top of the page to the left on the tool options bar. Click on this.

    If the arrow is not there, look in the options bar to the text tool, on the right, for a box with lines inside. Adobe changed the location and icon in later versions of the program.

  • How to get the value of DeviceKet in the QueryChangedDiskAreas function?

    Hello

    I'm trying to get the value of block changed to an ESXi Server virtual computer. I have the reference to object for the virtual machine must be passed to the QueryChangedDiskAreas function and snapshot. How can I get the 3rd parameter deviceKey - which I understand is the disc I get the Changed block for. Does someone can tell how I can get this value?

    Thank you

    . / Siva

    Hello Shiva!

    I suggest to use the property of the data object VM.config.hardware.device [] .key. You will for sure have to analyze the table first of all find the virtual disk in question. I can say that the deviceKey is the array index. But I would not count on that. In order to better use its practical value.

    Hope this helps

Maybe you are looking for