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

Tags: Database

Similar Questions

  • I need a query that selects the amount of records for each day of a table.

    I need a query that selects the amount of records for each day of a table.
    For example, the result would be:

    1 14 date
    Date 2-3

    etc.

    Any ideas?

    Sort:

    SELECT count ([IDCommentaire]), convert (varchar, dateAdded, 112)

    OF COMMENTSgroup by convert (varchar, dateAdded, 112)

  • 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!

  • Calendar of the apex; limit values for each day/cell

    Apex 4.2

    I'm working on a calendar widget to my page. The calendar will be specific sectors (using the abbreviation of sector space maximze) for each day. When you use the calendar, I noticed the sectors more you have, the cell for this day will begin to stretch down / vertically. I tried to change this so that a specific day / cell would show only a number of areas. For example, maybe one day 20 sectors are attributed to him, however, I only want to show 5 of them and then a text saying 'See more'. The text 'see more' will eventually be a link, but it's far from being the problem.

    Initially, the request for this was along the lines of:

    select
    the_id, the_date, the_sector, the sector_abbrev
    from Table
    where this = that
    

    It would show all sectors for all the days on the calendar. Yet once, I wanted to limit the output every day as some days would indicate all 20 sectors (their abbreviations), and some would be 3 or four in function. So to say that there are 30 sectors (10 1st), 4 of the 15, 12 on 20-4 on November 29. I want to allow only five abbreviations of sector which must appear in a cell until the link "see more" appears. I came up with the following query:

    Select
    the_sector_abbrev, the_id, the_date, the sector
    from Table
    where rownum <= 5 and (this = that)
    union all
    Select 'View More', null, null, null
    from dual
    

    I found that it would be limiting my calendar for showing that four areas throughout the month of November and not for each day / cell on the calendar. I am to discover that 'rownum' is perhaps not the way to go. I don't know how to specify for each of the calendar days rownum. I don't know how to capture every day / the Calendar cell. Maybe I need a more complicated or a subquery where clause. But overall, from my example above, the 1st show four of the sectors and then the link "See more", the 15th would show the four sectors and thats all, the 20th century would show four sectors and her "see more" link and so on.

    Any help on this would be greatly appreciated. Thanks in advance.

    NewApexCoder wrote:

    I had no idea of the possible application of solution would be too complex.

    It is not the case:

    with calendar_data as (
        select
            ins.sector_abbrev_name
          , sch.hwe_inspection_scheduling_id
          , sch.inspection_date
          , sch.instructions
          , sch.inspection_sector_id
          , sch.high_water_event_id
          , ins.inspection_sector_name
          , hwe.event_name
          , row_number()
                over (
                  partition by sch.inspection_date
                  order by sch.inspection_date, ins.inspection_sector_name) day_sector_rn
        from
            hwe_inspection_scheduling sch
              left join inspection_sectors ins
                on sch.inspection_sector_id = ins.inspection_sector_id
              left join high_water_events hwe
                on sch.high_water_event_id = hwe.high_water_event_id
        where
            (   sch.high_water_event_id = :p0_high_water_event_id
             or :p0_high_water_event_id is null))
    select
        inspection_sector_id
      , inspection_date
      , inspection_sector_name
      , sector_abbrev_name
      , ...
      , null -- Generate URL for sector links here
    from
        calendar_data
    where
        day_sector_rn <= 5
    union all
    select
        null
      , trunc(the_date) + 1 - interval '1' second
      , null
      , 'View More…'
      , ...
      , null -- Generate URL for "View More..." links here
    from
        calendar_data
    group by
        the_date
    having
        count(*) > 5
    
  • How to find the first max value for each item

    Hello

    I have the me_result of the table as below,

    SELECT * FROM me_result;

    ID     ||| ELITE     ||||||||||| FREQ_ITEM | COMBINED_STR | SUP
    1     ||; 1; 10; 2; 3; 4; 5; 7; 8. 1     ||||||||||||||; 1; 10; 2; 3; 4; 5; 7; 8 ||| 2
    2     ||; 1; 10; 2; 3; 4; 5; 7; 8. 2     ||||||||||||||; 1; 10; 2; 3; 4; 5; 7; 8 ||| 2
    3     ||; 1; 10; 2; 3; 4; 5; 7; 8. 3     ||||||||||||||; 1; 10; 2; 3; 4; 5; 7; 8 ||| 2
    4     ||; 1; 10; 2; 3; 4; 5; 7; 8. 4     ||||||||||||||; 1; 10; 2; 3; 4; 5; 7; 8 ||| 2
    5     ||; 1; 10; 2; 3; 4; 5; 7; 8. 5     ||||||||||||||; 1; 10; 2; 3; 4; 5; 7; 8 ||| 2
    6     ||; 10; 2; 3; 4; 5; 8; 9. 1     ||||||||||||||; 10; 2; 3; 4; 5; 8; 9; 1 ||| 1
    7     ||; 10; 2; 3; 4; 5; 8; 9. 2     ||||||||||||||; 10; 2; 3; 4; 5; 8; 9 ||| 2
    8     ||; 10; 2; 3; 4; 5; 8; 9. 3     ||||||||||||||; 10; 2; 3; 4; 5; 8; 9 ||| 2
    9     ||; 10; 2; 3; 4; 5; 8; 9. 4     ||||||||||||||; 10; 2; 3; 4; 5; 8; 9 ||| 2
    10     ||; 10; 2; 3; 4; 5; 8; 9. 5     ||||||||||||||; 10; 2; 3; 4; 5; 8; 9 ||| 2


    I need to find the first COMBINED_STR max for each element of the ELITE,
    I mean, max value is the max REGEXP_COUNT (combined_str,' ;')))

    really, I try to write down, but I had a lot of values for each ELITE and I need only the first, that
    SELECT * from me_result
    WHERE (ELITE, REGEXP_COUNT (combined_str,' ;')))) IN
    (SELECT ELITE, MAX (REGEXP_COUNT (combined_str,' ;'))))) ME_RESULT ELITE GROUP);

    I need the result to be as below.

    1; 1; 10; 2; 3; 4; 5; 7; 8-1; 1; 10; 2; 3; 4; 5; 7; : p
    6; 10; 2; 3; 4; 5; 8; 9 1; 10; 2; 3; 4; 5; 8; 9; 1 1

    any help please,.

    Published by: user11309581 on July 10, 2011 22:03

    Can be

    with t as
    (select 1     ID, ';1;10;2;3;4;5;7;8'     ELITE, 1     FREQ_ITEM, ';1;10;2;3;4;5;7;8' COMBINED_STR, 2 SUP from dual union all
    select 2     ,';1;10;2;3;4;5;7;8'     ,2     ,';1;10;2;3;4;5;7;8'     ,2 from dual union all
    select 3     ,';1;10;2;3;4;5;7;8'     ,3     ,';1;10;2;3;4;5;7;8'     ,2 from dual union all
    select 4     ,';1;10;2;3;4;5;7;8'     ,4     ,';1;10;2;3;4;5;7;8'     ,2 from dual union all
    select 5     ,';1;10;2;3;4;5;7;8'     ,5     ,';1;10;2;3;4;5;7;8'     ,2 from dual union all
    select 6     ,';10;2;3;4;5;8;9'     ,1     ,';10;2;3;4;5;8;9;1'     ,1 from dual union all
    select 7     ,';10;2;3;4;5;8;9'     ,2     ,';10;2;3;4;5;8;9'     ,2 from dual union all
    select 8     ,';10;2;3;4;5;8;9'     ,3     ,';10;2;3;4;5;8;9'     ,2 from dual union all
    select 9     ,';10;2;3;4;5;8;9'      ,4     ,';10;2;3;4;5;8;9'     ,2 from dual union all
    select 10     ,';10;2;3;4;5;8;9'     ,5     ,';10;2;3;4;5;8;9'     ,2 from dual
    )
    select ID,ELITE,FREQ_ITEM,COMBINED_STR,SUP
    from (
      SELECT ID,ELITE,FREQ_ITEM,COMBINED_STR,SUP, ROW_NUMBER() over (PARTITION BY ELITE order by id) RN
      FROM t
      WHERE (ELITE,REGEXP_COUNT(combined_str,';')) IN
        (SELECT ELITE,MAX(REGEXP_COUNT(combined_str,';')) FROM t GROUP BY ELITE)
    ) where RN=1
    order by id
    
    ID                     ELITE             FREQ_ITEM              COMBINED_STR      SUP
    ---------------------- ----------------- ---------------------- ----------------- ----------------------
    1                      ;1;10;2;3;4;5;7;8 1                      ;1;10;2;3;4;5;7;8 2
    6                      ;10;2;3;4;5;8;9   1                      ;10;2;3;4;5;8;9;1 1     
    
  • How to find the value max and min for each column in a table 2d?

    How to find the value max and min for each column in a table 2d?

    For example, in the table max/min for the first three columns would be 45/23, 14/10, 80/67.

    Thank you

    Chuck,

    With color on your bars, you should have enough experience to understand this.

    You're a loop in the table already.  Now you just need a function like table Max and min. loop.  And you may need to transpose the table 2D.

  • Max and Min value for each column

    Hello!

    Can someone help me to change my. VI? I want to get the Min and Max value for each column in the table in the appendices. Then I need to create two tables 1 d - the first with the min and the second with the max value.

    I've already solved the problem the solution is below

  • Delete based on specific hours for each day

    Hello

    I have a table with a field of date DD-MM-YYYY HH:MIN:SS
    Table contains date since 2006 and I just need to keep the entries with date DD-MM-YYYY 00:00 (midnight only registers for each day)

    Thanks in advance for any help.

    drbiloukos wrote:

    ...
    ...
    ...
    14-JAN-13
    14-JAN-13 12:01:00
    14-JAN-13 12:01:05
    14-JAN-13 12:02:03
    14-JAN-13 12:01:55
    14-JAN-13 12:02:13
    15-JAN-13
    15-JAN-13 12:01:00
    15-JAN-13 12:01:05
    15-JAN-13 12:02:03
    15-JAN-13 12:01:55
    15-JAN-13 12:02:13
    ...
    ...
    ...
    

    just need to keep accounts with

    ...
    14 JANUARY 13
    15 JANUARY 13

    LUN-JJ-AA 00:00

    that

    delete from table where date_col != trunc(date_col);
    or to keep the data
    update table set date_col = trunc(date_col)
    

    or you can add the new column

    alter table table_name add (new_date date);
    

    and update

    update table table_name set new_date = TO_DATE(TO_CHAR(old_date,'DD.MM.YYYY HH24:MI')||':00', 'DD.MM.YYYY HH24:MI' )
    

    Published by: Bawer on 16.01.2013 12:03

  • PSE8 - "date taken" set a fixed value for each edited image

    I've been monkeying with PSE8 for 6 months or more - not using the Organizer, but straight in the edition.

    In general, I'll create a template to a certain size (e.g., 1800 x 1200 pixels for printing 6 x 4 photos) and place an image on the template.

    After editing, I'll save the file under a new name in a new folder... and have noted recently that the "Date" property changed to exactly the same value for each image editing. 25/09/2010... Maybe it was the date of installation, I am not sure.

    In any case - it of annoying and has been touching to find help (which makes sense) online.

    Thanks in advance for any help you can give me.

    Possibly the date the template was created? PSE respects the camera EXIF data and always displays the date taken, but for digital images and new documents created in the program, it will use the file date.

  • Select the tables to Jdeveloper (master / detail)

    Hi, I need to add tables in Jdeveloper, the conecction to the database is allowed. But my problem is that I Don t know to select the tables and details of how master-.

    Thank you, the Colombia.

    you use what version of JDeveloper. ? If 11g, check this blog:

    http://andrejusb.blogspot.com/2009/03/ADF-faces-rich-client-popup-and-master.html

    concerning

  • How to select the values for each check box in a group of records

    Hello

    I have a requirement in form 10g. In this form there are 10 records are display each record has a checkbox is there if I click on the check box save number one and number three and make some changes in the text field (field adjustment is the number data type) and then finally, I want to see the total a total amount called field.

    In this, my question is how to select specific to a group of records records? and finally these selected records are inserted in a table.
    Because I am not able to read these records at a time.
    Is there any table to define a record group to fetch each of them individually for example Rec [1] Rec [2]... like this if yes please suggest me the steps how to do this.

    Thanks in advance
    Prasanna

    Published by: user10315107 on December 17, 2008 23:44

    OK, so you want to shoe the total amount in the form itself (I guess that somewhere under the dashboard lines?).

    You can do this easily using formulat elements:

    1 create a new item in your block where the field amount is places, set "section of the database" on the 'No', 'calculation mode' to the 'formula' and the 'formula' himself to something like:

    CASE WHEN :BLOCK.CHECKBOXITEM=CHECKVALUE THEN :BLOCK.AMOUNT+:BLOCK.ADJUSTMENT ELSE 0 END;
    

    This formula returns 0 if the checkboxitem is not checked, otherwise the sum of amount and adjustment (of course you can adjust the names of elements and the value for 'Checked')
    2. place the element in the layout, if you wish.
    3. set the property "Query all Records" to "true" for your block elements, this is necessary for the calculation to work
    3 create a control block to keep summary article in a, "Single Document" set to 'True '.
    4. place a new element in this control block, set 'Calcuation mode' to 'Summary', 'Summary block' to your block elements, 'Summary point' in newly created formula section in the block elements
    and function of synthesis for the "sum".
    5. place the element in the layout

    She's.

  • Determine a value for each record for the whole group

    < < Sorry I pasted erroneous results earlier > >

    Hello

    I have a table (in production, join the many tables, but for simplicity, I created a table), which has a few related accounts grouped by ACCT_GRP_ID I have to write a SQL (not a PL/SQL), who should have all columns of this table and an extra column "FLAG". For GA_CD = BBC, FLAG must have a value of 'No Show', if the APP_DT of at least a recording with the group is less than the current year also all the records in the group will have a value of 'Show '. For the record no BBC FLAG must always be 'Show '.

    DDLS
    {code}
    CREATE TABLE ACCOUNTS
    (NUMBER OF ACCT_GRP_ID,
    GA_CD VARCHAR2 (10),
    AGNT_NAME VARCHAR2 (50).
    NUMBER OF CASE_NUM
    NUMBER OF FUND_AMT
    DATE OF APP_DT,
    STATUS VARCHAR2 (10));

    INSERT INTO ACCOUNT VALUES (1, 'BBC', 'SAMANTHA, JOSE, 12345, 234.33, 2 AUG 2008', ' PLACED');
    INSERT INTO ACCOUNT VALUES (1, 'BBC', 'SAMANTHA, JOSE, 12346, 331,13, 24 APR 2009', ' PLACED');
    INSERT INTO ACCOUNT VALUES (1, 'BBC', 'SAMANTHA, JOSE, 12347, 201,27, 13 FEB 2009', ' PLACED');
    INSERT INTO ACCOUNT VALUES (2, 'BBC', ' MARK, ROSS, 12348, 98.12, 31 MAY 2009', 'PLACE' ");
    INSERT INTO ACCOUNT VALUES (2, 'BBC', ' MARK, ROSS, 12349, 121.00, 25 JUNE 2009', 'PLACE' ");
    INSERT INTO ACCOUNT VALUES (2, 'BBC', 'BRAND, ROSS, 12350, 11.00, 27 JUNE 2009', 'CLOSED');
    INSERT INTO ACCOUNT VALUES (3, 'BBC', "RAJ MALIK", 12351, 89.00, 31 DEC 2008', 'PLACED');
    INSERT INTO ACCOUNT VALUES (3, 'BBC', "RAJ MALIK", 12352, 22.00, 26 OCT 2008', 'PLACED');
    INSERT INTO ACCOUNT VALUES (4, 'BBC', 'SHANE, WILLS', 12353, 443.00, 7 JUNE 2009', 'PLACE');
    INSERT INTO ACCOUNT VALUES (5, 'BBC', 'JANE, WALLACE, 12354, 74.00, 17 JAN 2009', ' PLACED');
    INSERT INTO ACCOUNT VALUES (NULL, 'BBC', 'ROSY, BETH', 12355, 124.00, 21 MAR 2009', 'PLACE');
    INSERT INTO ACCOUNT VALUES (NULL, 'STAR', 'TINA, WZWICK', 22330, 89.00, 31 DEC 2008', 'PLACED');
    INSERT INTO ACCOUNT VALUES (NULL, 'STAR', 'YANA, KORVIN', 27351, 22.00, 26 OCT 2008', 'PLACED');
    INSERT INTO ACCOUNT VALUES (NULL, 'STAR', 'SARA, YUI', 22352, 443.00, 7 JUNE 2009', 'PLACE');
    INSERT INTO ACCOUNT VALUES (NULL, 'STAR', 'MIKE, TROY, 22453, 74.00, 17 JAN 2009', ' PLACED');

    COMMIT;
    {code}

    Required result:
    {code}
    APP_DT GA_CD AGNT_NAME STATE BOITE_ FUND_ ACCT_ INDICATOR
    AMT NUM GRP_ID
    1 SAMANTHA, JOSE PLACE 12347 201.27 BBC 13/02/2009 no show
    1 SAMANTHA, JOSE PLACE 12346 331.13 BBC 24/04/2009 no show
    1 SAMANTHA, JOSE PLACE 12345 234.33 BBC 08/02/2008 no show
    MD2 BBC BRAND, ROSS CLOSED 12350 11 6/27/2009 see the
    MD2 BBC BRAND, ROSS PLACED 12349 121 6/25/2009 see the
    2 BRAND of BBC, ROSS PLACE 12348 98.12 show of 31/05/2009
    3 BBC RAJ MALIK not PLACED 12352 22 10/26/2008 no show
    3 BBC RAJ MALIK not PLACED 12351 89 12/31/2008 no show
    4 BBC SHANE, WILLS PLACE 12353 443 6/7/2009 see the
    5 BBC JANE, WALLACE PLACE 12354 74 1/17/2009 see the
    STARS of MIKE, TROY PLACED 22453 74 1/17/2009 see the
    See the BBC ROSE, BETH PLACED 12355 124 3/21/2009
    STAR SARA, YUI PLACED 22352 443 6/7/2009 see the
    TINA, WZWICK STAR PLACED 22330 89 12/31/2008 see the
    YANA STAR, KORVIN PLACED 27351 22 10/26/2008 see the
    {code}

    As in the results Group 1 has a record with the date of 2008 for the whole group getting 'No Show'. Group 2 has all the records this year, so he gets the 'Show '.
    Help, please!

    Published by: Kuul13 on June 25, 2009 13:31

    Published by: Kuul13 on June 25, 2009 13:43
    I think I'm really having a BAD BAD day... Sorry again... I don't need the domain TOT_FUND_AMT...

    Hello

    Thanks for posting the DDL and DML statements. This helps a lot.

    I don't understand the output, however. Do you want to really two rows of output for each row in the table? The tot_fund_amt is copied from somewhere else? More important still, the results do not include the new flag column. Isn't the point of all of this question? It's good to describe how the indicator is calculated, but you have to show, too.

    I think you want analytical MIN function to find the first app_dt in each group, like this:

    SELECT  a.*
    ,     CASE
              WHEN  ga_cd = 'BBC'
              AND   MIN (app_dt) OVER ( PARTITION BY  ga_cd
                                          ,              acct_grp_id
                                        )  < TRUNC (SYSDATE, 'YYYY')
                    THEN  'No Show'
                    ELSE  'Show'
         END     AS flag
    FROM     accounts   a
    ;
    

    Output:

    . ACCT
      _GRP GA                     CASE     FUND
       _ID _CD  AGNT_NAME         _NUM     _AMT APP_DT     STATUS FLAG
    ------ ---- --------------- ------ -------- ---------- ------ -------
         1 BBC  SAMANTHA, JOSE   12345   234.33 08/02/2008 PLACED No Show
         1 BBC  SAMANTHA, JOSE   12346   331.13 04/24/2009 PLACED No Show
         1 BBC  SAMANTHA, JOSE   12347   201.27 02/13/2009 PLACED No Show
         2 BBC  MARK, ROSS       12348    98.12 05/31/2009 PLACED Show
         2 BBC  MARK, ROSS       12349   121.00 06/25/2009 PLACED Show
         2 BBC  MARK, ROSS       12350    11.00 06/27/2009 CLOSED Show
         3 BBC  RAJ, MALIK       12351    89.00 12/31/2008 PLACED No Show
         3 BBC  RAJ, MALIK       12352    22.00 10/26/2008 PLACED No Show
         4 BBC  SHANE, WILLS     12353   443.00 06/07/2009 PLACED Show
         5 BBC  JANE, WALLACE    12354    74.00 01/17/2009 PLACED Show
           BBC  ROSY, BETH       12355   124.00 03/21/2009 PLACED Show
           STAR TINA, WZWICK     22330    89.00 12/31/2008 PLACED Show
           STAR SARA, YUI        22352   443.00 06/07/2009 PLACED Show
           STAR MIKE, TROY       22453    74.00 01/17/2009 PLACED Show
           STAR YANA, KORVIN     27351    22.00 10/26/2008 PLACED Show
    

    Note that the NULL acct_grp_id is a group. PARTITION BY acct_grp_id is of course necessary, but we must also, PARTITION BY ga_cd all non-BBC lines will be included in this group. In other words, we are unwilling reported as 'No Show', all ROSY just because TINA or JANA had an early app_dt.

  • getting the last area for each case

    Hello all;

    I have a table with the following information below
    create table tmp_a
    (
           idv number(30),
           personid number(30),
           Area varchar2(200),
           dateadded date,
           is_close number(2)
    );
    
    insert into tmp_a
      (idv, personid, area, dateadded, is_close)
    values
      (1, 10001, 'ZONE_A', sysdate, 1);
      
    insert into tmp_a
      (idv, personid, area, dateadded, is_close)
    values
      (2, 10002, 'ZONE_B', sysdate, 0);
      
    insert into tmp_a
      (idv, personid, area, dateadded, is_close)
    values
      (3, 10003, 'ZONE_A', sysdate, 0);
    
    insert into tmp_a
      (idv, personid, area, dateadded, is_close)
    values
      (4, 10003, 'ZONE_A', sysdate, 0); 
      
    Now, I'd like to get this below
    idv   Personid   Area        Dateadded                           Is_clode
    4       10003   Zone_A     3/3/2011 1:00:37PM               0
    2       10002   Zone_B     3/3/2011 12:17;14PM              0
    the output is based on the fact if there are duplicates associated with the area, the query should choose the last... In this case, the last being for zone_A is idv 4.
    Please note, idv is a primary key. How can I do this? Any help is appreciated. Thank you.
    select  max(idv) keep(dense_rank last order by dateadded,idv) idv,
            max(personid) keep(dense_rank last order by dateadded,idv) personid,
            area,
            max(dateadded) dateadded,
            max(is_close) keep(dense_rank last order by dateadded,idv) is_close
      from  tmp_a
      group by area
      order by area
    /
    
           IDV   PERSONID AREA                           DATEADDED             IS_CLOSE
    ---------- ---------- ------------------------------ ------------------- ----------
             4      10003 ZONE_A                         03/03/2011 13:12:50          1
             2      10002 ZONE_B                         03/03/2011 13:12:50          0
    
    2 rows selected.
    
    SQL> 
    

    SY.

  • Type a table defined clusters to hold configuration data - definition of default values for each element of the array

    Hello

    I was wondering if I could get some information and opinions on the use of an array of type defined clusters to store configuration data.  I am creating a program to test several EHR and wanted to have a control of type defined for each HAD with the information needed to create the DAQmx tasks for all signals for it must HAVE.  I am eager to do so that the data are encoded in hard and not in a file that the user might spoil.

    Controls of type def are then put into a Subvi who chooses as appropriate, one based on the enumeration of Type DUT connected to a case structure.

    I have problems with the control of the defined type.  I see issues when you try to save a configuration unique to each element of the array in the array of clusters.  Somehow, it worked at first, but now by clicking on "Operations on the data--> default font of the current value ' on individual elements of the cluster or the entire cluster (array element) does not save data when I re - open the command def.  What I am doing wrong?  I'm trying to do something with the berries of the clusters that I shouldn't do?

    I enclose one of the defined reference type controls.  I tried to change it bare to see if that helped, but no luck.

    To reproduce, change the resource string for the element 0 of the array and do the new value by default.  Then close the def of type, and then reopen it.  The old value is always present in this element.  The VI is saved in LabVIEW 2012.

    The values of a typedef are not proprigated to the instances of the control. They get if created WHEN data values have changed. They will be not updated with the changes to come. You must create a VI specifically to hardcode your values or to implement a file based initialization. The base file would be much better and more flexible. If you don't want users to change the data simply encryption. There is a wedding blowfish library that you can download.

  • SQL - find the minimum value for each separate record...

    Hi all

    I have a table like this in SQL Server

    Date of sale of product
    A date
    A date
    A date
    B date of
    B date of
    C date
    C date
    C date

    I would like to write a query to find the minimum date (i.e. the date
    the first sale) for each product

    Thus, the expected results would be

    Date of sale of product
    A date min
    B date of min
    C date of min

    How can I do this using SQL Server?

    any help is greatly appreciated!

    Thank you!

    Product SELECTION, MIN (sale_date)
    From your_table
    GROUP BY product

    Etienne

Maybe you are looking for