Query to get the previous value

Hello guys,.

I have a problem to do a simple Oracle's SQL query.

I will give an example. Imagine a table (test) with the following data:

DATE DEPRECIATION AMORTIZATION

-----------------------------------------------------------------------------------------------

01/01/2013 1.00 1.00

02/05/2013 1.00 2.00

03/08/2013 1.00 3.00

04/12/2013 1.50 4.50

13/05/2013 1,00 5.50

22/06/2013 1,00 6.50

17/07/2013 1,00 7.50

08/11/2013 1.00 8.50

27/09/2013 1,00 9.50

10/01/2013 0.50 10.0

11/01/2013 1,00 12.0

12/01/2013 1.00-13.0

If I want to recover the accumulated depreciation from June to December, is simple:

SELECT DEPRECIATION

OF THE TEST

WHERE DATE BETWEEN to_date ('01-06-2013 ',' DD - MM - yyyy")

AND to_date ('01-12-2013 ',' DD - MM - yyyy")

However, I would like to create a field that question to bring the accumulated depreciation of the

previous month (month of May), without changing the WHERE clause. Where I work, we use views to make such a request, but the performance is terrible.

Anyone know the solution to this problem or can offer some advice?

1f7629cd-28fe-4FC3-9CA0-2a2e51824e79 wrote:

Solomon, this is the result I want. However, in a dynamic way.

I don't have a need to communicate their data.

I think you speak WITH clause. You don't commit CREATE TABLE + INSERT, WITH the clause is a quick way to create your table on the fly. All you need is:

Select t.*,

accumulated_deprecation - prev_mon_accum_deprecation deprecation

t

where dt between to_date('01-06-2013','dd-MM-yyyy') and to_date('01-12-2013','dd-MM-yyyy')

/

Of course, you must change the table names and column in your names. I don't know what happened to your last post, but on this basis:

SELECT m.dat_mov_patr,

m.val_valor_real,

m.val_depr_acumulada,

m.val_depr_acumulada - m.val_valor_real

OF mov_patrimonial m

WHERE m.dat_mov_patr > to_date (January 3, 2005 ', "dd-MM-yyyy")

/

And it's all simple arithmetic - no need to use all functions. Column val_depr_acumulada accumulated disapproval of the month 1 to the current month. Column val_valor_real is the disapproval of the current month. Val_depr_acumulada - val_valor_real is therefore accumulated disapproval of the month 1 month.

SY.

Tags: Database

Similar Questions

  • Get the previous value of the sequence

    Oracle version
    10.2.0

    sequence
    CREATE SEQUENCE ADM_SQ_TABLE_GROUP
      START WITH 21
      MAXVALUE 999999999999999999999999999
      MINVALUE 1
      NOCYCLE
      CACHE 20
      NOORDER;
    Main table
    CREATE TABLE ADM_TL_TABLE_GROUPMST
    (
    TBGM_KEYID   VARCHAR2(6)    NOT NULL,
    TBGM_NAME    VARCHAR2(50)   NOT NULL,
    TBGM_CODE    VARCHAR2(15)   NOT NULL,
    CONSTRAINT PK_ADM_TL_TABLE_GROUPMST PRIMARY KEY (TBGM_KEYID),
    CONSTRAINT UK_TBGM_CODE UNIQUE(TBGM_CODE)
    );
    Insert values
    INSERT INTO ADM_TL_TABLE_GROUPMST VALUES (adm_sq_table_group.NEXTVAL, 'PCS TABLE GROUP', 'PCS');
    Table Details
    CREATE TABLE ADM_TL_TABLE_GROUPDTL
    (
    TBGD_KEYID  VARCHAR2(8) NOT NULL,
    TBGD_MASTERID VARCHAR2(6)    NOT NULL,
    TBGD_TABLENAME  VARCHAR2(30)    NOT NULL,
    TBGD_ORDER      NUMBER(2)   NOT NULL,
    CONSTRAINT PK_ADM_TL_TABLE_GROUPDTL PRIMARY KEY (TBGD_KEYID),
    CONSTRAINT FK_TBGD_MASTERID FOREIGN KEY (TBGD_MASTERID) REFERENCES  ADM_TL_TABLE_GROUPMST(TBGM_KEYID)
    );
    Insert the script
    INSERT INTO ADM_TL_TABLE_GROUPDTL VALUES (adm_sq_table_group.NEXTVAL, adm_sq_table_group.CURVAL, 'PCS_TL_MST', 1);
    How to get previously generated sequence values

    Use the VOTING class if you use PL/SQL

  • Dynamic SQL query to get the unique value of list in a column

    I have two tables: tblWorkers and tblSkills. tblWorkers has a column, skills, which is populated by a field of multiple-checkbox with one or more skill_IDs of tblSkills, so each tblWorkers.Skills consists of a list of one or more comma-delimited values. For any Skill_ID, I need to generate a list of all workers with the appropriate skills, so I tried to do something in the direction of SELECT WorkerName FROM tblWorkers WHERE IN of skills (skills, #FORM. Skill_ID #)... or WHERE skills (ListFind (skills, #FORM. Skill_ID #))... etc.? My results (once I have had data type mismatches of the road) return all workers, not just those with the desired skills. There must be an easy way to do... How people with a little more experience CF/SQL I do this?

    > each tblWorkers.Skills consists of a list of one or more comma-delimited values

    This is your problem. You store a list of values that you want to access power/query separately in a single column. You will have to burst in a separate table.
    TblWorkers

    TblSkills

    TblWorkerSkills
    mapping table of many workers with skills.

    If you do not change your data model now, you will constantly be butting your head against that.

  • Get the old value of the element when sending, why?

    I am looking for the value of the newly submitted to the building of a controller method.  However, the previous value is obtained, not the new value that is entered in this area before submitting the page, and I don't know why.

    OAMessageTextInputBean tableNameSearchBean = (OAMessageTextInputBean) webBean.findChildRecursive ("tableName");
    String tableName = tableNameSearchBean.getText (pageContext);

    What I am doing wrong?  How do you get the value of an item that should be part of the shipment?

    Thank you

    Hello

    Can you please use--> tableNameSearchBean.getValue (pageContext) and check the result?

    In addition, if you can explain with an example of prior value and a new, it will be easier to help.

    Kind regards

    Zahid

  • SQL query to get the NULL records after the last matching flag

    I have a xx1 table with id and flag columns. So I want the data in this table, after the last flag matched. I want that data to id 7 in the rooms. Even if the id 2,3,5 are null flag 'Y' was at 6. ID so I need a query to get the data of the xx1 table after the last correspondence flag (from 7 to 9 id).

    SQL > create table xx1

    2 (identification number,

    3 flag varchar2 (10));

    Table created.

    SQL > insert into xx1 values (1, 'Y');

    1 line of creation.

    SQL > insert into values xx1 (2, null);

    1 line of creation.

    SQL > insert into values xx1 (3, null);

    1 line of creation.

    SQL > insert into xx1 values (4, 'Y');

    1 line of creation.

    SQL > insert into values xx1 (5, null);

    1 line of creation.

    SQL > insert into xx1 values (6, 'Y');

    1 line of creation.

    SQL > insert into values xx1 (7, null);

    1 line of creation.

    SQL > insert into values xx1 (8, null);

    1 line of creation.

    SQL > insert into values xx1 (9, null);

    1 line of creation.

    SQL > select * from xx1.

    FLAG OF THE ID

    ---------- ----------

    1. IS

    2

    3

    4. IS

    5

    6. IS

    7

    8

    9

    9 selected lines.

    SQL >

    Hello

    user11164339 wrote:

    Hi Frank - when I run the query, I don't see the results data.

    I get

    FLAG OF THE ID

    ----- ----------

    7

    8

    9

    What you do differently?

  • Exception while trying to get the selected value for the choice of SelectOne in ADF Mobile

    I added the following code after arriving through this post https://forums.oracle.com/thread/2536419

    DCBindingContainer dcBindings = (DCBindingContainer) BindingContext.getCurrent () .getCurrentBindingsEntry ();

    DCIteratorBinding iterBind = (DCIteratorBinding) dcBindings.get ("facilitySelectItems");

    Attribute String = (String) iterBind.getCurrentRow () .getAttribute (0);

    But Jdeveloper complained class BindingContext wasn't available and I get the jar file adfm.jar has not been added to the project. I added it manually the path C:\JDeveloper11r24\oracle_common\modules\oracle.adf.model_11.1.1\adfm.jar. Once I've deployed code on an android emulator, I get the below error. Can someone please?

    07-25 13:18:03.812: D/CordovaLog (869): [SEVERE - oracle.adfmf.framework - adf.mf.internal - logError] request: {classname: oracle.adfmf.framework.api.Model; method: evaluateMethodExpression; params: [0: #{pageFlowScope.IBCMSearchBean.getSearchParams}] [1:] [2: {}] [3:] ;} exception: {message: oracle/adf/model/binding/DCBindingContainer (unsupported major.minor version 50.0); the severity: ERROR; .Guy: oracle.adfmf.framework.exception.AdfException; .exception: true ;}}}

    The version of the compiler maximum the JDev shows that 1.4. And I'm using version 11.1.2.4.0 for JDeveloper. The JDK version is 1.6.0_24.

    Sorry I missed the question!

    First of all, to get the value of selectedItem in selectOneChoice do not have another function in the domain controller. Here is an excellent article by Frank that explains this. Or you can use the below function to get the selected value immediately. Here the market is the value of selectOneChoice attribute. I wasn't aware of this method until you have read this article.

    {} public void getAndSetMarketValue (market of the object)

    ValueExpression ve = (ValueExpression) AdfmfJavaUtilities.getValueExpression ("#{bindings.marketSelectItems}", Object.class);

    AmxAttributeBinding attrBinding = (AmxAttributeBinding) ve.getValue (AdfmfJavaUtilities.getAdfELContext ());

    access the iterator that populates the list of values in

    the selectManyChoice component

    AmxIteratorBinding amxListIterator = attrBinding.getIteratorBinding ();

    the AmxIteratorBinding is a wrapper for the BasicIterator

    iterator which sets out the information we need

    ListIterator BasicIterator = amxListIterator.getIterator ();

    for each index value, query the name of the service (you can

    access and attribute from the line) to display

    SelectedValue = string

    (String) listIterator.getAttributeValueAtIndex (((New Integer ((String) market))) .intValue (), "Value");

    }

    Second, you can use #{row} in commandLink's action since it is something that is evaluated when the user clicks on the link and we do not have access to #{line} after that the entire component is rendered. To remedy this give an action for the commandlink which is a function in the bean and the function of bean back to the action of the link selected.

    ListOfReports.amx

    .......

    .......

    LoginBean.java

    ......

    public String returnClickValue() {}

    Option of string = AdfmfJavaUtilities.evaluateELExpression("#{viewScope.selectedItem}").toString ();

    return option;

    }

    ......

  • How to get the current value of db in backing bean

    Hello

    I use jdeveloper 11.1.2.3.0

    I would like to know how I could access the old value of an attribute in backing bean.
    I know I can get it in terms of EntityImpl with the getPostedAttribute function,
    but as I see that I'm not allowed to access this function in the ViewImpl.
    I get this error:
    Error (151,33): getPostedAttribute (int) has protected access to oracle.jbo.server.EntityImpl.

    Could you help her?
    What is the right way to get the current value on db in backing bean?

    Thank you very much!

    You can add a transitional attribute to the entity object to hold the old value of the desired attribute, then you can add this attribute to the view object.
    Check [url http://www.youtube.com/watch?v=iKVIiK0FBXI] retrieve the previous value of an attribute ADF BC

  • Query to get the last change in the particular column

    Hello

    [Update]
    I need help to find the last change to a particular to a table column.

    tell the table as
    t_address (phone_number, first_name, user_id, change_date)

    I need to find what was her last phone number change happened.
    Well, the date of change is updated for any changes in this table. I want to understand the change_date only when a particular field has changed (from the previous value). It seems a little complicated for me.

    t_address (phone_number, first_name, user_id, change_date)

    say for any change of phone_number, name it will be an entry in this table t_address. and change_date will be the inserted date.

    say

    USR_ID phone_number name change_date
    Hari 123 Henderson 12/12/2011
    Hari hari 123 12/11/2011
    Hari hari 345 12/10/2011

    now my requirement is to get 12/11/2011 as on that particular date, the phone number has changed from previous value.


    Please suggest.

    Published by: user7807429 on Sep 10, 2012 11:51

    Hello

    WITH t_address AS (
    SELECT 'hari' usr_id, 123 phone_number, 'harinath' first_name ,DATE '2011-12-12' change_date FROM dual UNION ALL
    SELECT 'hari' usr_id, 123 phone_number, 'hari' first_name ,DATE '2011-12-11' change_date FROM dual UNION ALL
    SELECT 'hari' usr_id, 345 phone_number, 'hari' first_name ,DATE '2011-12-10' change_date FROM dual
    )
    SELECT  usr_id
           ,phone_number
           ,prev_phone_number
           ,first_name
           ,change_date
    FROM    (
        -- Select only the rows where the phone number changed
        -- and max phone change date for each user
        SELECT  usr_id
               ,phone_number
               ,first_name
               ,change_date
               ,prev_phone_number
               ,MAX(change_date)
                OVER (PARTITION BY usr_id
                      ORDER BY change_date
                      RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
                      ) max_change_date
        FROM    (
            -- Select the data together with the phone number of the previous row
            SELECT  usr_id
                   ,phone_number
                   ,first_name
                   ,change_date
                   ,LAG(phone_number)
                    OVER (PARTITION BY usr_id
                          ORDER BY change_date
                          ) prev_phone_number
            FROM    t_address
            )
        -- check for difference with decode because phone_number might be NULL
        WHERE   DECODE( prev_phone_number, phone_number, 1, 0 ) = 0
        )
    WHERE   change_date = max_change_date;
    
    USR_ID PHONE_NUMBER PREV_PHONE_NUMBER FIRST_NAME CHANGE_DATE
    ------ ------------ ----------------- ---------- -----------
    hari            123               345 hari       11.12.2011 
    

    You can include the current value if you join more intimate in the select t_user.

    Concerning
    Marcus

  • to get the total value as application even if item_number is added

    Hi all

    I have the following query with me
    SELECT   SUM (  (NVL (f.calc_cement_sk, f.calc_amount) * NVL (f.item_price, 0)
                    )
                  - (  NVL (f.calc_cement_sk, f.calc_amount)
                     * NVL (f.item_price, 0)
                     * (NVL (f.dis_per, 0) / 100)
                    )
                 ) total,
             h.slurry_type, h.stage_id, h.slurry_vol_actual
        FROM xxnp_opn_joblog_est_002 f,
             xxnp_opn_joblog_001 j,
             xxnp_opn_joblog_slurry_003 h,
             qp_secu_list_headers_v qw
       WHERE j.opn_job_desc = 'K/D/KD43/UG187/1338/D/0211/1'
         AND f.opn_joblog_001_id = j.opn_joblog_001_id
         AND j.contract = qw.NAME
         AND h.opn_joblog_001_id = j.opn_joblog_001_id
         AND h.opn_joblog_007_id = f.opn_joblog_007_id
         AND h.opn_joblog_006_id = f.opn_joblog_006_id
    GROUP BY h.stage_id, h.slurry_type, h.slurry_vol_actual
    the result I get is


    SLURRY_TYPE TOTAL STAGE_ID SLURRY_VOL_ACTUAL
    9,562.59 lead 1 490
    2,184.84 1 80 tail
    1,091.73 reload 1 56
    3,431.64 tail 2 100
    when i add f.item_number to the above query as shown below
    
    SELECT   SUM (  (NVL (f.calc_cement_sk, f.calc_amount) * NVL (f.item_price, 0)
                    )
                  - (  NVL (f.calc_cement_sk, f.calc_amount)
                     * NVL (f.item_price, 0)
                     * (NVL (f.dis_per, 0) / 100)
                    )
                 ) total,f.item_number,
             h.slurry_type, h.stage_id, h.slurry_vol_actual
        FROM xxnp_opn_joblog_est_002 f,
             xxnp_opn_joblog_001 j,
             xxnp_opn_joblog_slurry_003 h,
             qp_secu_list_headers_v qw
       WHERE j.opn_job_desc = 'K/D/KD43/UG187/1338/D/0211/1'
         AND f.opn_joblog_001_id = j.opn_joblog_001_id
         AND j.contract = qw.NAME
         AND h.opn_joblog_001_id = j.opn_joblog_001_id
         AND h.opn_joblog_007_id = f.opn_joblog_007_id
         AND h.opn_joblog_006_id = f.opn_joblog_006_id
    GROUP BY h.stage_id, h.slurry_type, h.slurry_vol_actual,f.item_number
    
    
    the field total gets split and gives value corresponding to each item_number
    
    i am giving the ouptut for stage 1
    ITEM_NUMBER TOTAL SLURRY_TYPE STAGE_ID SLURRY_VOL_ACTUAL
    5011.5 1020101001 lead 1 490
    1308.93 1020102002 lead 1 490
    127.215 1020111001 lead 1 490
    138.92 1020112001 lead 1 490
    686 1020113001 lead 1 490
    550,5 1020113002 lead 1 490
    1739.52 1020222010 lead 1 490
    1517.1 1020101001 1 80 tail
    379.5 1020102003 1 80 tail
    83.2 1020103001 1 80 tail
    166.53 1020104001 1 80 tail
    38.511 1020111001 1 80 tail
    1064,7 1020101001 reload 1 56
    27,027 1020111001 reload 1 56


    If we add up the values in the total field to the head, tail, charge that we get 9562.59,2184.84,1091.73 respectively

    kindly Guide
    to get the total value as application even if item_number is added
    thanking in advance

    Hello

    You can do this by enclosing it with another selection

    select
    total, slurry_type, stage_id, slurry_vol_actual,
    sum(total) over (partition by slurry_type, stage_id, slurry_vol_actual) from (
    your actual select
    )
    

    concerning

  • Query to get the data of the column and the metadata in the same set of results.

    Is it possible to build a query to get the values of the columns in a table and also be able to get some metadata (data type, data_length, data_precision, data_scale) for columns in the same set of results.

    If I use a join, have a common value to join on the two tables?

    you use a cross join, not requiring common values.

    create table T (n number, d date, v varchar2(30));
    insert into T values (1,sysdate,'ABC');
    commit;
    
    select C.column_name, c.data_type, c.data_length,
    case c.column_id
     when 1 then to_char(T.N)
     when 2 then to_char(T.D)
     when 3 then T.V
    end VALUE
    from USER_TAB_COLUMNS C, T
    where C.table_name='T'
    order by c.column_id;
    
  • Need to get the original values

    Hello friends,
    In my scenario, I need to get the original values
    for ex: in a single table of data lines are (R, A, J, A), in another table are given in the lines (R, A, J, E, S, H) and I need to cancel R & J where it is present in both tables. Then I need to cancel one at table 1 because there is an only A is present in table 2 and another should remain as original value. Then the County he came like 4 (A, E, S, H)

    chris227 wrote:
    any benefit here?
    OK, we know that the outer joins can be in does not exist,

    what the implementation plans

    compare the execution plan please

    for your query

    |   0 | SELECT STATEMENT           |                            |    10 |   350 |    32  (63)| 00:00:01 |
    

    and my

    |   0 | SELECT STATEMENT           |                            |    10 |   320 |     9  (56)| 00:00:01 |
    
    SQL> select * from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    
  • How to check the previous value of the element in a multi-record block

    Oracle Version: 10 g
    Forms Version: 10 g

    Hi all
    Hello everyone, I have a multi-dossier block in a form where one of the values of elements is of LOV.user can select the value of LOV.

    If once the user selects the value of LOV and moves to the next of the multi-file record, and selects the value of LOV again, I shouldn't allow users to select the previous value of the user in order to avoid duplication of records.

    and important remark is that I should get there before you save it in the database because once registered in the database I can compare the values and hide the previous value.


    Any help will be appreciated.


    Thanks and greetings

    This is a question frequently asked in the forum! There are several different solutions. Take a look at the following articles. Both will perform the necessary verification of duplicates.
    Forms - registration of treatment group (value in double check...
    or
    Avoid records duplicated in a block

    If none of these solutions don't work for you, search the forum for other options.

    Hope this helps,
    Craig B-)

    If someone useful or appropriate, please mark accordingly.

  • How set the value of a LOV in CO prgramatically and get the Pkey value?

    Hello

    I need to get the Primaykey LOV will return and set a value for a LOV, say ItemLOV in a page through CO. How can I achieve this?

    Req:
    1. set the nom_element, say "DELL_1618" so that the page displays this in the LOV.
    2 get the PK value returned by LOV in the backend in an attribute of VO say Item_ID, ' 100009881'.

    Thank you
    Sicard.

    Hi Santosh,

    Sorry, I responded to general LOV scenario, but want to put it right,

    You need run your LOV query to the controller for the "DELL_1618" element using the prepared command, get the value of the value display and Id and assign the LOV and FormVlaue in the PR of the controller.

    Kind regards
    Out Sharma

  • Get the selected value in the list drop-down/messagechoice

    Hi friends,
    App R12.
    I create a drop-down list programmatically in the process request:

    OAMessageChoiceBean OAMC = oapagecontext.getWebBeanFactory () .createWebBean (OAWebBeanConstants.MESSAGE_CHOICE_BEAN, null, oapagecontext, null) (OAMessageChoiceBean);

    oamc.setPickListViewUsageName ("MyVO1");
    oamc.setListValueAttribute ("MyId");
    oamc.setListDisplayAttribute ("MyDescription");
    oamc.setID ("xxMypicklist");
    oamc.setRendered (Boolean.TRUE);
    oawebbean.addIndexedChild (oamc);

    This shows the list of choices and there MyVO1 query search results.

    Now, I want retrieve value MyId in the processFromRequest (after pushing a button on the screen). I do the following:

    OAApplicationModule am = pageContext.getApplicationModule (webBean);
    ...
    MyVOImpl myvoimpl = (MyVOImpl) am.findViewObject("MyVO1");
    MyVORowImpl PicklistRow = myvoimpl.getCurrentRow ((MyVORowImpl));
    NUMBER auxId = (NUMBER) PicklistRow.getAttribute ("MyId"); THIS SENTENCE GIVES A NULL POINTER EXCEPTION

    Then..., is not enough to find the original Version? and get the rank "perceive"... and then get the desired attribute?

    Do I need to load data from MyVO1 into myvoimpl? How? How to get the folder selected on the screen?

    Many thanks for any help. It is very urgent for me to solve this problem. Dev guide does not help with this kind of usual problems.
    Jose L.

    Hello

    u can not get the value of this way, becz you try to get the value of the original Version which is used for bean of choice message, to get the value selected in this field of choicebean message, you must get the VO initialized for this page, both would be different VO, you can opt for the following approach

    (1.) an another VO wiil be there in your page get implemented to capture the data on this page, the attribute of this VO would be added to your field of beans of choice, need to understand that VO and and capture your selected value.

    or the other way is

    2.), you can change your code in the same way in the pR method

    OAMessageChoiceBean OAMC = oapagecontext.getWebBeanFactory () .createWebBean (oapagecontext, OAWebBeanConstants.MESSAGE_CHOICE_BEAN, null, "XXMypicklistBean) (OAMessageChoiceBean);

    and get the selected value in pFR method in this way

    OAMessageChoiceBean getCHBean = (OAMessageChoiceBean) (webBean.findIndexedChildRecursive ("XXMypicklistBean"));

    String val = (String) getCHBean.getValue (pageContext));

    thanx

    Pratap

  • Where does FireFox get the default value for a preference of. What is the format of the file that contains the default value?

    Where does FireFox get the default value for a preference of. What is the format of the file that contains the default value? I need the actual default value for an individual preference.
    Topic: config shows some default values, but I need the source from which everything: config returns to the default value.
    Any help in this direction is greatly appreciated.

    User Agent

    Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x 64; Trident/4.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)

    The preferences that are not hidden if they have by default are stored in two JavaScript text files in the Firefox program folder
    You can open them in a tab in Firefox through these links:
    resource:///defaults/pref/firefox.js
    resource:///greprefs/all.js

    (702598/forum/1/702598)

Maybe you are looking for