Select the lines with the maximum value for a date where another column is different from 0

Hello

I need to write a query on a table (called DEPRECIATION) that returns only the rows whose date maximum (PERENDDAT_0 column) for a specific record (identified by AASREF_0), and where the other column in the table called DPRBAS_0 is different from 0.

If DPRBAS_0 is equal to 0 in all the lines of a specific record, then return the line with date maximum (PERENDDAT_0 column).

To be clearer, I give the following example:

Suppose we have the following data in the table of DEPRECIATION:

AASREF_0 PERENDDAT_0 DPRBAS_0
I2011001074331/12/20150
I2011001074331/12/20140
I2011001074331/12/20130
I2011001085612/31/20160
I2011001085631/12/20150
I2011001085631/12/2014332
I2014001223812/31/2016445
I2014001223831/12/2015445
I2014001223831/12/20140

The query must return only the following lines:

AASREF_0 PERENDDAT_0 DPRBAS_0
I2011001074331/12/20150
I2011001085631/12/2014332
I2014001223812/31/2016445

Thanks a lot for your help!

This message was edited by: egk

Hello Egk,

The following query works for you.

SELECT AASREF_0, PERENDDAT_0, DPRBAS_0

FROM (SELECT AASREF_0,

PERENDDAT_0,

DPRBAS_0,

ROW_NUMBER)

DURING)

AASREF_0 PARTITION

ORDER BY

CASE WHEN DPRBAS_0 <> 0 THEN 1 OTHER 0 END DESC,.

PERENDDAT_0 DESC)

RN

DEPRECIATIONS)

WHERE rn = 1

Tags: Database

Similar Questions

  • How to select the default value for a choice of selection when page.jsff load

    Hello everyone, I am newbie have little problem

    I have problem with soc (selectOneChoice)
    in this case I ' to select the default value of af: SelectOneChoice (select first selectItem) when the page is finished loading

    < af:selectOneChoice label = "" Jenny Bahan: "id = 'soc1'"
    autoSubmit = 'true '.
    valueChangeListener = "#{WHStockSetReleaseBean.cekJenisBahan} '"
    Binding = "#{WHStockSetReleaseBean.v_jenisBahan}" >
    * < af:selectItem label = "GBB" value = "GBB" id = "si2" / > * = > i'want to select this value for the default (select first selectItem)
    < af:selectItem label = "GBP" value = "GBP" id = "si1" / >
    < / af:selectOneChoice >

    If someone help me to solve this problem

    THX
    agungdmt

    Hello

    try to set the attribute value to af:selectOneChoice like that.

    
    

    Kind regards
    Sicard.

  • Select the last value for each day of the table

    Hello!

    I have a table that contains several measures for each day. I need two queries on this table, and I'm not sure how to write them.

    The table stores the rows (sample data)
    *DateCol1                 Value       Database*
    27.09.2009 12:00:00       100           DB1
    27.09.2009 20:00:00       150           DB1
    27.09.2009 12:00:00       1000          DB2
    27.09.2009 20:00:00       1100          DB2
    28.09.2009 12:00:00       200           DB1
    28.09.2009 20:00:00       220           DB1
    28.09.2009 12:00:00       1500          DB2
    28.09.2009 20:00:00       2000          DB2
    Explanation of the data in the sample table:
    We measure the size of the data files belonging to each database to one or more times a day. The value column indicates the size of the files of database for each database at some point (date in DateCol1 European model).


    What I need:
    Query 1:
    The query must return to the last action for each day and the database. Like this:
    *DateCol1       Value      Database*
    27.09.2009        150          DB1
    27.09.2009       1100          DB2
    28.09.2009        220          DB1
    28.09.2009       2000          DB2
    Query 2:
    The query should return the average measurement for each day and the database. Like this:
    *DateCol1       Value      Database*
    27.09.2009       125          DB1
    27.09.2009      1050          DB2
    28.09.2009       210          DB1
    28.09.2009      1750          DB2
    Could someone please help me to write these two queries?

    Please let me know if you need further information.

    Published by: user7066552 on September 29, 2009 10:17

    Published by: user7066552 on September 29, 2009 10:17

    Why two queries when it suffice ;)

    SQL> select dt
      2       , db
      3       , val
      4       , avg_val
      5    from (
      6  select dt
      7       , val
      8       , db
      9       , row_number () over (partition by db, trunc (dt)
     10                                 order by dt desc
     11                            ) rn
     12       , avg (val) over (partition by db, trunc (dt)) avg_val
     13    from test)
     14   where rn = 1
     15  order by dt
     16  /
    
    DT        DB           VAL    AVG_VAL
    --------- ----- ---------- ----------
    27-SEP-09 DB2         1100       1050
    27-SEP-09 DB1          150        125
    28-SEP-09 DB2         2000       1750
    28-SEP-09 DB1          220        210
    
  • Take the minimum value for table data

    I'm storing test data in a table, with the hope that I can output the minimum value of the data. So far, I have used the table of max/min but can't make it work how I want. The test runs continuously in a loop of the holder. I get the minimum values in the table, but I would like to change the number of samples that the table contains, before it generates a minimum. The other option is that I run the test for a period of time (e.g. 3 seconds) and the table stores the data for this time then output 1 minimum value for the entire period.

    My current configuration VI is attached.

    Very appreciated

    Chris

    The size of the array in your VI is determined by the number of samples that you collect in your DAQ assistant, who is now 100 samples.  Never more, never less.

    How many samples do you want before you determine the minimum?

    Maybe what you really want to do is to build the table in the while loop and store it in a shift register, and when the loop has repeated enough times, then you take the minimum of built table.

  • How to get the empty values for common data for a column?

    Hello
    I have a table whose data is like this:
    DEPT_ID     STATUS     USER_ID     ART_ID
    
    7     R     1234     0000001
    7     P     2411     0000002
    7     Q     1231     0000003
    7     S     7676     0000004
    3     R     6776     0000005
    3     S     7869     0000006
    6     Q     787     0000007
    6     W     5656     0000008
    .......more data like this
    How can we get this are data in this format:
    7     R     1234     0000001
         P     2411     0000002
         Q     1231     0000003
         S     7676     0000004
    3     R     6776     0000005
         S     7869     0000006
    6     Q     787     0000007
         W     5656     0000008

    In SQL * Plus, you can use the PAUSE command

    SQL> break on deptno;
    SQL> ed
    Wrote file afiedt.buf
    
      1  select deptno, ename
      2    from emp
      3*  order by deptno
    SQL> /
    
        DEPTNO ENAME
    ---------- ----------
            10 CLARK
               MILLER
               KING
            20 FORD
               smith
               ADAMS
               SCOTT
               JONES
            30 SM0
               TURNER
               BLAKE
               MARTIN
               ALLEN
               WARD
               PAV
               BAR
    
    16 rows selected.
    

    In SQL, you must use an analytic function

    SQL> ed
    Wrote file afiedt.buf
    
      1  select (case when deptno = prior_deptno
      2               then null
      3               else deptno
      4            end) deptno,
      5         ename
      6    from (select deptno,
      7                 lag(deptno) over (order by deptno, ename) prior_deptno,
      8                 ename
      9            from emp
     10*          order by deptno, ename)
    SQL> /
    
        DEPTNO ENAME
    ---------- ----------
            10 CLARK
               KING
               MILLER
            20 ADAMS
               FORD
               JONES
               SCOTT
               smith
            30 ALLEN
               BLAKE
               MARTIN
               SM0
               TURNER
               WARD
               BAR
               PAV
    
    16 rows selected.
    

    Justin

  • How to choose the maximum value in a column of a table by using the cursor and iteration

    Hello everyone
    I have a table loan_detail
    and a column inside loan_amount
    now I want to take the values in this table with the cursor, then using iteration that I want to take a max value of him using this slider
    Here is my table
    LOAN_AMOUNT
    
    100
    200
    300
    400
    500
    5600
    700
    I could make using the concepts of single loop, but when I tried to do by using the slider I wasn't able to do.
    Concerning
    Prost

    You can get the maximum value for a particular column in SQL, PLSQL needn't; Always avoid PLSQL so you can do it in SQL. But always as an example:

    declare
    number of Temp: = 0;
    Start
    for news in some loan_amt of loan_detail
    loop
    If (temp
    end if;
    end loop;
    dbms_output.put_line (temp);
    end;

    Edited by: Mahanam January 5, 2011 03:11

  • Get the highest value of acquired data

    Hi, how can I get the highest value of data according to data acquired using the accelerometer ADXL345 and LINX in LabVIEW?

    I want the highest data to be shown with a flag. However, the data being shown are always the last acquired data. My problem would be what happens if the highest data somewhere at the beginning or in the middle of all the acquired data? How to display the highest data using an indicator?

    Here's a look at my front, block diagram, and sample of the acquired data.

    From the front panel, the basic indicator of detected last poster 0.1929 (amplitude), which is the last value. But looking at the Excel file, the highest data are data which is 0.2013. The highest, I want to be displayed on the indicator not the last value. How do I do that?

    Thank you!

    I gave you an example of what you need to do - it is not okay if wire you the new value and the old value for the X or Y - it will always return the maximum of the two values so the order doesn't matter. It would have been more useful if you had posted what you tried the max & min. You need a registry to offset inside the loop (like I did with my while loop). If you only want to display the maximum value for each iteration of the loop for external, you must initialize the shift register by plugging a 0 to its terminal on the left. A shift register her pinned the value of the last run - probably not what you want here.

  • SQL - last selection query save values for each date in term

    Hello

    Can anyone help me please with my problem.

    I'm trying to get the last balance recorded for each day of specific box (1 or 2) in a given period of days of the database ms access using ADOTool.

    I'm trying to get this information with SQL query but so far without success.

    My table looks like this:

    Name of the table: TestTable

    Date         Time      Location  Box  Balance
    20.10.2014.  06:00:00     1       1    345
    20.10.2014.  12:00:00     1       1    7356
    20.10.2014.  18:45:00     1       1    5678
    20.10.2014.  23:54:00     1       1    9845
    20.10.2014.  06:00:02     1       2    35
    20.10.2014.  12:00:04     1       2    756
    20.10.2014.  18:45:06     1       2    578
    20.10.2014.  23:54:10     1       2    845
    21.10.2014.  06:00:00     1       1    34
    21.10.2014.  12:05:03     1       1    5789
    21.10.2014.  15:00:34     1       1    1237
    21.10.2014.  06:00:00     1       2    374
    21.10.2014.  12:05:03     1       2    54789
    21.10.2014.  15:00:34     1       2    13237
    22.10.2014.  06:00:00     1       1    8562
    22.10.2014.  10:00:00     1       1    1234
    22.10.2014.  17:03:45     1       1    3415
    22.10.2014.  22:00:00     1       1    6742
    22.10.2014.  06:00:05     1       2    562
    22.10.2014.  10:00:16     1       2    123
    22.10.2014.  17:03:50     1       2    415
    22.10.2014.  22:00:10     1       2    642
    23.10.2014.  06:00:00     1       1    9876
    23.10.2014.  09:13:00     1       1    223
    23.10.2014.  13:50:17     1       1    7768
    23.10.2014.  19:47:40     1       1    3456
    23.10.2014.  21:30:00     1       1    789
    23.10.2014.  23:57:12     1       1    25
    23.10.2014.  06:00:07     1       2    976
    23.10.2014.  09:13:45     1       2    223
    23.10.2014.  13:50:40     1       2    78
    23.10.2014.  19:47:55     1       2    346
    23.10.2014.  21:30:03     1       2    89
    23.10.2014.  23:57:18     1       2    25
    24.10.2014.  06:00:55     1       1    346
    24.10.2014.  12:30:22     1       1    8329
    24.10.2014.  23:50:19     1       1    2225
    24.10.2014.  06:01:00     1       2    3546
    24.10.2014.  12:30:26     1       2    89
    24.10.2014.  23:51:10     1       2    25
    ...
    

    Let's say that the period is 21.10.2014. -23.10.2014. and I want to get the last balance recorded for zone 1. for each day. The result should look like this:

    Date         Time      Location  Box  Balance
    21.10.2014.  15:00:34     1       1    1237
    22.10.2014.  22:00:00     1       1    6742
    23.10.2014.  23:57:12     1       1    25
    

    So far, I managed to write a query that gives me the balance so that a SINGLE date (date more time in the table), but I need balance for EACH date in a specific period.

    My incorrect code (has not managed to implement "BETWEEN" for the dates...):

    SELECT TestTable.[Date], TestTable.[Time], TestTable.[Location], TestTable.[Box], TestTable.[Balance]
    FROM TestTable
    WHERE Time=(SELECT MAX(Time)
    FROM TestTable
    WHERE Location=1 AND Box=1 );
    

    TNX!

    NP

    Here's the correct query (just copy - paste):

    SELECT
    T1.Date,
    T1.Time,
    T1.Location,
    T1.Box,
    T1.Balance
    FROM TestTable T1
    INNER JOIN (
    SELECT
    MAX(Time) AS Max_Time
    FROM TestTable
    WHERE Location=1 AND Box=1 AND Date BETWEEN #10/27/2014# AND #11/1/2014#
    GROUP BY Date) T2
    ON T1.Time=T2.Max_Time;
    

    The problem is in the SELECTION within the INNER JOIN. This SELECTION selects the time max for each date, because we want this and then the entire table, we choose filelds we want, but now we have only fields with the time max.

    Here is a really good explanation of INNER JOIN if anyone is interested--> JOINT INTERNAL

    Peace!

  • Select the emp with a maximum salary for each hr.emp manager_id

    Hello
    Can someone help me to do this without doing any partitioning or analytical f:

    Select the emp with a maximum salary for each hr.emp manager_id.

    HR. EMPLOYEES Table Description: =.
    EMPLOYEE_ID
    FIRST NAME
    LAST_NAME
    HIRE_DATE
    JOB_ID
    SALARY
    COMMISSION_PCT
    MANAGER_ID
    DEPARTMENT_ID

    TX, all the guys
    Mario

    Hi, Mario,.

    Here's one way:

    SELECT       *
    FROM       hr.employees
    WHERE       (manager_id, salary) IN (
                                          SELECT    manager_id
                              ,               MAX (salary)
                              FROM     hr.employees
                              GROUP BY  manager_id
                                   )
    ;
    

    mario17 wrote: Hi,
    Can someone help me to do this without doing any partitioning or analytical f:

    Do you mean analytical functions?
    Why you don't want to use the analytical functions? Analytical functions, permitting the simpler, more robust and more effective to achieve these results, wouldn't you want that?

  • Selection of lines with the range Paging VO

    Hello

    JDev 11.1.2.4

    I created a VO based on an OA. I added a transitional attribute in the original Version, this attribute is named Selelected of type Boolean initialized to false (default value Expression: false-Expression of Refresh value: false). That VO appears as an af:table. The attribute is displayed as selectBooleanCheckbox. The VO is set with an access mode of range Paging and a size of 28.

    < af:selectBooleanCheckbox value = "#{row.bindings.Selected.inputValue} '"

    label = "#{bindings." VwRhdPortfolioTranWrkSend11.hints.Selected.label}.

    required = "#{bindings." VwRhdPortfolioTranWrkSend11.hints.Selected.mandatory}.

    shortDesc = "#{bindings." VwRhdPortfolioTranWrkSend11.hints.Selected.tooltip}"id ="it1' autoSubmit = 'true '.

    valueChangeListener = "#{pageFlowScope.portfolioTransferBean.onWorkSelection}" >

    < f: validator binding="#{row.bindings.Selected.validator}"/ >

    < / af:selectBooleanCheckbox >

    The table shows the 25 lines. The user clicks one of the checkbox to select a line. The valueChangeListener is called with the new value (auto submit = true) as expected. Then the user scroll down for another "page" in the table, new lines are displayed. Then it scrolls to the first page. The previous selected checkbox is reset as not selected. The selection is lost.

    Is this expected behavior? If so how do you get a selection of lines with a VO of range paging.

    Thank you

    Try to create the transitional attribute in OT instead of VO.

    See you soon

    AJ

  • get the value of the maximum value of a column for a particular type

    Hello.
    I have a query which returns the output something like

    Type of VersionNo ID ProductID VersionID category unusual
    1130 16650 16650 1193 5 Category1
    1130 16650 16650 1205 5 Category2
    1130 16650 16650 1242 5 category3
    1130 16650 1130 1001 1 Category1
    1130 16650 1130 1081 1 category3
    1131 16656 16656 1193 4 Category1
    1131 16656 16656 1205 4 Category2
    1131 16656 16656 1240 4 category3
    1131 16656 1131 1001 1 Category1
    1131 16656 1131 1081 1 category3

    I want to see the result that all the VersionId for the same ID values should have the same value for the category and it should be the value that is there for the maximum versionNo for a particular Type of «» Something like


    Type of VersionNo ID ProductID VersionID category unusual
    1130 16650 16650 1193 5 Category1
    1130 16650 16650 1205 5 Category2
    1130 16650 16650 1242 5 category3
    1130 16650 1130 1193 1 Category1
    1130 16650 16650 1205 1 Category2
    1130 16650 1130 1242 1 category3
    1131 16656 16656 1193 4 Category1
    1131 16656 16656 1205 4 Category2
    1131 16656 16656 1240 4 category3
    1131 16656 1131 1193 1 Category1
    1131 16656 16656 1205 1 Category2
    1131 16656 1131 1240 1 category3

    Does anyone know how to do this?

    Ok
    Try:

    WITH test_data AS (
    SELECT 1130 RecID, 16650 ProductID,  16650 VersionID, 1193  Category,  5 VersionNo, 'Category1' Type FROM DUAL UNION ALL
    SELECT 1130, 16650, 16650, 1205, 5, 'Category2' FROM DUAL UNION ALL
    SELECT 1130, 16650, 16650, 1242, 5, 'Category3' FROM DUAL UNION ALL
    SELECT 1130, 16650, 1130, 1193, 1, 'Category1' FROM DUAL UNION ALL
    SELECT 1130, 16650, 1130, 1205, 1, 'Category2' FROM DUAL UNION ALL
    SELECT 1130, 16650, 1130, 1242, 1, 'Category3' FROM DUAL),
    -- end test data
    max_data AS (
    SELECT RecID, ProductID, VersionID, Category, VersionNO, Type
      FROM test_data td1
     WHERE VersionNo = (
      SELECT MAX(VersionNo)
        FROM test_data td2
      WHERE td1.RecID = td2.RecID
         AND td1.ProductId = td2.ProductID))
    SELECT RecID, ProductID, VersionID, Category, VersionNO, Type
      FROM max_data
      UNION
    SELECT md1.RecID, md1.ProductID, td1.VersionID, md1.Category, td1.VersionNO, md1.Type
      FROM max_data md1
      JOIN test_data td1
     ON (md1.RecID = td1.RecID AND md1.ProductID = td1.ProductID)
    ORDER BY 1,2,3,5, 6
    
         RECID  PRODUCTID  VERSIONID   CATEGORY  VERSIONNO TYPE
    ---------- ---------- ---------- ---------- ---------- ---------
          1130      16650       1130       1193          1 Category1
          1130      16650       1130       1205          1 Category2
          1130      16650       1130       1242          1 Category3
          1130      16650      16650       1193          5 Category1
          1130      16650      16650       1205          5 Category2
          1130      16650      16650       1242          5 Category3
    

    And you simply:

    WITH max_data AS (
    SELECT RecID, ProductID, VersionID, Category, VersionNO, Type
      FROM test_data td1
     WHERE VersionNo = (
      SELECT MAX(VersionNo)
        FROM test_data td2
      WHERE td1.RecID = td2.RecID
         AND td1.ProductId = td2.ProductID))
    SELECT RecID, ProductID, VersionID, Category, VersionNO, Type
      FROM max_data
      UNION
    SELECT md1.RecID, md1.ProductID, td1.VersionID, md1.Category, td1.VersionNO, md1.Type
      FROM max_data md1
      JOIN test_data td1
     ON (md1.RecID = td1.RecID AND md1.ProductID = td1.ProductID)
    ORDER BY 1,2,3,5, 6
    
  • The default value for a property with data of type boolean

    Hi all

    Is it a system preference setting, where the default value for a property with data of type boolean can be a Virgin? I want to keep the value by default in a vacuum, but every time I save the property even after empty selection, the default value changes to FALSE.

    Capture.JPG

    In this case Boolean doesn't help you, you mayneed to create a chain of ownership and have true/false / "" as your list of values

  • HP DV7-3063cl laptop PC: what is the maximum temperature for safe operation of the DV7 3063 cl with the upgrade of the 640 M CPU?

    I have recently restored a HP DV7 3063 cl laptop that died a hot mother (MB). I replaced the MB with a new Board of Directors of HP when the price has been reduced to $100, updated the CPU with an announced as new AMD 640 M and applied Arctic Silver on CPU and graphics chips. I put in 4 G memory cool, got the computer to work and installed Windows 10.

    The computer seems to run very hot and stopped twice from overheating during its first period of 2 weeks when it there was not a lot of calculating, fan was run at top speed at all times, and the laptop was high to allow good airflow below.

    According to the program of the Open Hardware Monitor, the CPU had reached 97-99 C a few times. I bought support cooling a player and that seems to help a lot, dropping the temperature to 20 ° C.

    What is the maximum temperature for safe operation of the DV7 with the upgrade of the 640 M CPU?

    Anything more than 90 c is too hot. You can specify the processor and the motherboard you have installed?

    Also if this from the Manual:

    Thermal paste is used on 1 CPU and heat sink section 2 that the services it. Thermal pads are used on the chip Northbridge 3 and 4, the graphical subsystem chip 5 contact Northbridge and graphics/heatsink contact 6. Thermal material replacement is included with all kits of spare parts of processor, heatsink and system board.

    So unless you have changed the cooling system to heat composed on the chip graphic you should have used a thermal buffer. Without the pad, it may leave just a small hallway and destroy the cooling properties. You can use a shim in copper or other piece of something metal to fill the void, but if you just put the heat sink down on the video chip you won't get optimal even with thermal cooling paste.

  • Simulator Device.xml file has a tag with an attribute of memory, what are the optional values for this attribute of the os?

    In the Device.xml file, it starts with the tags of the os. Each os has a memory attribute. What are the optional values for the attribute memory?

    Can we really control the memory for the simulators?

    0x85000F03
    0x8C000F03
    0x87000F03
    0x84001503
    0x86001503
    0x04001507
    0x0F001507
    0x0C001404
    0x0D001404
    0x0E001404
    0x0D000D04
    0x16000D04
    0x05001504
    0x07001504
    

    These values refer to specific hardware configurations are simulated.  They should not be changed.

  • Persistent for the subtraction of the background image collection (how to get the maximum value of each pixel in a series of images IMAQ)

    Hi all

    I have a system of LabVIEW which takes advantage IMAQ tools and features of the Vision Development Module.  A useful feature that I put in place is to be able to take a snapshot of the video stream and then subtract this single image among the subsequent images.

    What I want to do is to collect a series of images instead of one, and then create a unique image of these frameworks is just the maximum value of pixels in each pixel (a bit like a display persistent).

    It would probably be very easy to be implemented by converting the image to a table and then by doing math number on the table and then turning into an image, but I hope that someone here may know how to use the IMAQ/VDM tools to do this in a way more compact.

    Thank you very much

    MK

    How about using Max comparison IMAQ operation?

Maybe you are looking for

  • I want my new tabs open at the end of the row of tabs, how do I do this?

    When I open a new tab, I would like to open at the end of the line of tabs, not next to the tab I'm on now. I'm used to the opening on the end, as it did in older versions of Firefox. I'm sure it's an easy fix, but I can't find anything in the option

  • HDD upgrade for Satellite M30 304

    Hello I have a Satellite M30-304. It has a 40 GB hard drive and I would like to upgrade to 120 or 160 GB. Could if it you please let me know the specification of compatible drive for M30 - 304?Can what max HDD M30-304 capacity have? Detailed specific

  • Error-61499 occurred at niFpgaTimingViolation_InitializeHighlightData.vi

    Hello I am an old user of LabVIEW FPGA and lately I have had a problem to get a certain vi to compile.  A certain VI of my writings for the PXI-7953R always target failure of compilation with a violation of the synchronization.  When I click on "Anal

  • Assign to ICM Application

    Hello Seems to be an easy question. In ICM 11.0 how to assign the script to a number? Concerning Mohamed Helmy

  • updates to Adobe hypercrap? WTF

    If you can´t download offline installers more is that correct?only these downloads hyperdrive BS?Adobe expects people to download gigabytes of data for EACH system on which they install adobe software?These product managers think?