Choosing unique record based on latest date

I have a column, say Name, in which a person's name appears with multiple transactions. Each transaction has an unique date. I want to return just the latest transaction by date for each person.
If I write my select as:
select Name, Trans_Dt from <Table>;
I of course get a list of all transactions listing person and date.
I've tried this:
select Name, Trans_Dt from <Table>
group by Trans_Dt having greatest(Trans_Dt).
This doesn't work. Any suggestions?

select name, trans_dt
from
   select
      Name,
      Trans_Dt,
      max(Trans_Dt) over(partition by name) as max_trans_date
   from <Table>
where Trans_Dt= max_Trans_trans_date;Would be one way.

Similar Messages

  • Finding the record with the latest date

    Post Author: sconlon
    CA Forum: General
    Hi,I am using CR 8 with an Access database which has a table that holds (multiple) sales records for each of our clients. I want to create a report that lists only the latest sale from each client.  I am thinking that I first need to group by client and then create a sub-report that prints the necessary details of sales record with the latest date of sale.  It's this last bit that I cannot figure out how to do.  Can anyone suggest a way of doing this?Many thanks,sconlon

    Post Author: Jagan
    CA Forum: General
    Charliy's suggestion if fine, and does require sorting and displaying in the group header/footer according to the sort order. In case it's not clear, when you print in the group header you are using the first record's data; when you print in the group footer you are using the last record's data (first and last within the group that is).
    Personally, I'd group on the client have a group selection formula of:
    {table.date_field} = maximum({table.date_field}, {table.client_id})
    so that there's no date sort required as you'll only get one record per client group - assuming that each record has a unique date of course. I'd probably still suppress the details section and display in the group footer, but it wouldn't matter if you use the details section either.
    I believe the benefit with the group selection formula is that any summary formulas, running totals etc. you use would only have the one record per client to work on, rather than including all of the suppressed records too.

  • Select record according to latest date

    I have two fields in my DB table , one is region and other is date .
    There are many records for region (R1 lets say).
    My requirement is that I want the record (only one record) with the latest date for this region .

    hi,
    try like this.
    SELECT - aggregate
    Syntax
    ... { MAX( [DISTINCT] col )
        | MIN( [DISTINCT] col )
        | AVG( [DISTINCT] col )
        | SUM( [DISTINCT] col )
        | COUNT( DISTINCT col )
        | COUNT( * )
        | count(*) } ... .
    Effect
    As many of the specified column labels as you like can be listed in the SELECT command as arguments of the above aggregate expression. In aggregate expressions, a single value is calculated from the values of multiple rows in a column as follows (note that the addition DISTINCT excludes double values from the calculation):
    MAX( [DISTINCT] col ) Determines the maximum value of the value in the column col in the resulting set or in the current group.
    MIN( [DISTINCT] col ) Determines the minimum value of the content of the column col in the resulting set or in the current group.
    AVG( [DISTINCT] col ) Determines the average value of the content of the column col in the resulting set or in the current group. The data type of the column has to be numerical.
    SUM( [DISTINCT] col ) Determines the sum of the content of the column col in the resulting set or in the current group. The data type of the column has to be numerical.
    COUNT( DISTINCT col ) Determines the number of different values in the column col in the resulting set or in the current group.
    COUNT( * ) (or count(*)) Determines the number of rows in the resulting set or in the current group. No column label is specified in this case.
    reward if useful.

  • Getting the last set of records based on a Date Field

    Hi All
    i have the followings data set in a table
    TRACK_ID_GRP     TRACK_ID_NBR     TRACK_SAMPLE_ID     START_DATE
    970150                      129700104071     64260                        8/6/2002
    970150                      229700101893     64261                        8/6/2002
    970150                     149700101893     64262                        8/6/2002
    970150                       97015011     79252                        9/19/2005
    970150                       97015023     79255                        9/19/2005
    970150                       97015013     79253                         9/19/2005
    970150                       97015021     79254                        9/19/2005
    970040                      129900105213     56155                         9/26/2000
    970040                                 1101     29841                        6/9/1998
    970040                       97004023     143349                        10/28/2008
    970040                              2101     29842                        6/9/1998
    970040                        97004021     143348                        10/28/2008
    970040                       97004011     143346                        10/28/2008
    970040                      149700101903     64196                       7/16/2002
    970040                              2301     29844                      6/9/1998
    970040                         97004013     143347                         10/28/2008
    970040                                  1301       29843                        6/9/1998I need to get only those records with the latest date and i'm using the following query
    SELECT t.track_id_grp, t.track_id_nbr, t.track_sample_id,
           MAX (t.start_date) OVER (PARTITION BY t.track_id_grp) AS start_date
      FROM track_table t
    WHERE t.track_id_grp IN ('970150', '970040')And i'm getting the following dataset
    TRACK_ID_GRP     TRACK_ID_NBR     TRACK_SAMPLE_ID     START_DATE
    970040                      1.299E+11     56155     10/28/2008
    970040                      1101                     29841     10/28/2008
    970040                      97004023                     143349     10/28/2008
    970040                      2101                     29842     10/28/2008
    970040                      97004021                     143348     10/28/2008
    970040                      97004011                     143346     10/28/2008
    970040                      1.497E+11     64196     10/28/2008
    970040                      2301                     29844     10/28/2008
    970040                      97004013                     143347     10/28/2008
    970040                      1301                     29843     10/28/2008
    970150                      1.297E+11     64260     9/19/2005
    970150                      97015011                     79252     9/19/2005
    970150                      97015021                     79254     9/19/2005
    970150                      2.297E+11     64261     9/19/2005
    970150                      97015013                     79253     9/19/2005
    970150                      97015023                     79255     9/19/2005
    970150                      149700101903     64262     9/19/2005And i was expecting the following dataset
    TRACK_ID_GRP     TRACK_ID_NBR     TRACK_SAMPLE_ID     START_DATE
    970150                      97015011                             79252     9/19/2005
    970150                      97015023                             79255     9/19/2005
    970150                      97015013                             79253     9/19/2005
    970150                      97015021                             79254     9/19/2005
    970040                      97004023                             143349     10/28/2008
    970040                      97004021                             143348     10/28/2008
    970040                      97004011                             143346     10/28/2008
    970040                      97004013                             143347     10/28/2008I was expecting to get only those records with the latest date, instead i'm getting all the records with the max date in it, please need help or advice.
    Thanks

    Try this -
    SELECT track_id_grp, track_id_nbr, track_sample_id, start_date
      FROM (SELECT t.track_id_grp, t.track_id_nbr, t.track_sample_id,
                   t.start_date,
                   ROW_NUMBER () OVER (PARTITION BY t.track_id_grp, t.track_sample_id ORDER BY t.start_date DESC)
                                                                            AS rn
              FROM track_table t
             WHERE t.track_id_grp IN ('970150', '970040'))
    WHERE rn = 1let me know if that works.
    Edited by: Sri on Apr 28, 2011 9:24 AM

  • Create a record based on From date and To Date in CRM 2015 Plugins

    Hi all
    in my account screen i have two date field from date and Todate and i have one child entity member when i am creating a
    new account then based on from date and to date number of child record should be created
    for example in account screen
    if from date=2/1/2015 and 
       To date=31/03/2015
    then number of child record should be created
    in this manner 
    from date      to date 
    2/1/2015       31/01/2015
    01/02/2015     28/02/2015
    1/03/2015      31/03/2015

    Hi,
    OK. It seems you want to create 3 records (custom child entity) where the first has the same From Date as the Account and goes up to the end of the month, and the other records go from there.
    This logic can be implemented via a Plugin that could run on the create and update of these fields on Accounts. From the Plugin, you can set up the logic and fill the records with the necessary information.

  • Discoverer: Capturing record with the latest date among others

    Hi there,
    I would appreciate if anyone can help me in Discoverer10g Report. The report gives me the following results. Let me know if any more info needed.
    Example:
    Plan Cov St Dt Amt Elec. Dt Name Rt St dt Comm Ann Enrl Cov St Dt
    Basic Life     01-JAN-2011     76000.00     11-NOV-2010     Stephanie     01-JAN-2011          2.63      68.40     11-NOV-2010     
    Basic Life     01-JAN-2011     76000.00     29-OCT-2010     Stephanie     01-JAN-2011          2.63      68.40     29-OCT-2010     (Yes)
    Basic Life     01-JAN-2011     177000.00     29-OCT-2010 Shanika     01-JAN-2011          6.13      159.30     29-OCT-2010     (Yes)
    Basic Life     01-JAN-2011     214000.00     19-NOV-2010     Nicole     01-JAN-2011          7.41      192.60     19-NOV-2010     (Yes)
    Basic Life     01-JAN-2011     214000.00     29-OCT-2010     Nicole     01-JAN-2011          7.41      192.60     29-OCT-2010
    What I want to capture is latest date record from available records of the same employee and if there is only one record, I would want that too. In short, the ones which has '(yes)' at the end.
    What function can I use to get the desired results.
    Thank you!
    NN

    Hi Tamir,
    I used the the function(for another report which has similar situation) you mentioned but it gives me an error saying-
    ORA-01858: a non-numeric character was found where a numeric was expected.
    Its is OAB module indeed. some how due to date issue during our Insurance Vendor changes, I get multiple records of the same employees with some blank fields. See the example below.
    *4.36     07-AUG-2010     31-DEC-4712     07-AUG-2010     07-AUG-2010     21206*
    NULL     07-AUG-2010     31-DEC-4712     07-AUG-2010          21206
    3.95     01-JAN-2010     31-DEC-4712     01-JAN-2010     01-JAN-2010     21206
    Now out of three I need the one in bold letters. and there are other employees having just one record like
    Amt   Cov_St_DT         Cov_End_Dt       Rate_St_Date    Rt_Effective Dt  EEID
    1.45     15-SEP-2010     31-DEC-4712     15-SEP-2010     15-SEP-2010     22777
    7.65     01-JAN-2010     31-DEC-4712     01-JAN-2010     01-JAN-2010     21298
    so I need the single records as well as latest(date) record of multiple records of one employee.
    Let me know if you need more information.
    One more thing- is there any way to see the actual query I am running?(not sql Inspector)
    Thank you!
    797174
    p.s Thank you for the earlier reply.
    Edited by: 797174 on Dec 21, 2010 2:18 PM

  • Remove duplicate rows based on latest date

    Hi Julius, There are various ways to achive this but I would think an optimized way of doing it by making use of (Sorter and) an Aggregator transformation(s), see how.. Sort your input records at SQ level if it's a relational source or else use a Sorter tx (that's why I mentioned Sorter tx in braces in abvoe line) to sort the input rows on Stage_ID and Date, both in Ascending order, thus you get the latest date record at the end in the list per common Stage_IDs. Now, connect to Aggregator (must be right next to the sorter in order to not to loose the sorted data), and enable the Group By for Stage_ID port. By nature, aggregator tx will push the last record of the group by port or last record of the complete data set if no group by port mentioned. So, you will get recent row per Stage_ID. Try and get back to us if you have any questions or run into issues,-Rajani

    I have a target table I need to split up: stage_id / date / case / blah / blah100 / 01-jan-2015 / 223 / 32 / 323100 / 01-apr-2015 / 224 / 32 / 322 the stage_id column cannot have more than 1 of the same record, so, i need to keep the latest record (01-apr-2015) in this target table, then remove the old one and put it into a dimension table any suggestions for how to accomplish this? please let me know if more info is needed thanks!

  • Selecting unique records- Removing consecutive same data

    HI,
    am having a table where in some x,y,msg_date_info fields are there...here the data is in huge number...i need to fetch the data from this table subject to the following query conditions.
    SELECT  X longit,Y latit,MSG_DATE_INFO,row_number() over (order by MSG_DATE_INFO asc) SlNo FROM
    (SELECT distinct x,y,MSG_DATE_INFO,row_number() over (order by MSG_DATE_INFO desc) r
      FROM TRACKING_REPORT WHERE MSISDN='123456789') WHERE R between 1 and 20this works fine...
    here one more thing i want to add up...this query results in 20 rows as expected and i want to filter the records if consecutive x and y values of these rows are same and give only unique values of x and y(condition that same x and y can be there somewhere in the order of data).
    this example will show what is my requirement in detail....and this is the output of the above query
    >
    80.20550609     13.09469998     08-Mar-10 19:23:23     1
    80.20550609     13.09469998     08-Mar-10 19:28:37     2
    80.20087123     13.09437811     08-Mar-10 19:33:25     3
    80.20550609     13.09469998     08-Mar-10 19:38:24     4
    80.20550609     13.09469998     08-Mar-10 19:43:25     5
    80.20550609     13.09469998     08-Mar-10 19:48:25     6
    80.20087123     13.09437811     08-Mar-10 19:53:25     7
    80.20087123     13.09437811     08-Mar-10 19:58:24     8
    80.20550609     13.09469998     08-Mar-10 20:03:25     9
    80.20087123     13.09437811     08-Mar-10 20:08:24     10
    80.20550609     13.09469998     08-Mar-10 20:13:24     11
    80.20087123     13.09437811     08-Mar-10 20:18:37     12
    80.20550609     13.09469998     08-Mar-10 20:23:32     13
    80.20550609     13.09469998     08-Mar-10 20:28:25     14
    80.20550609     13.09469998     08-Mar-10 20:33:23     15
    80.20550609     13.09469998     08-Mar-10 20:38:24     16
    80.20550609     13.09469998     08-Mar-10 20:43:24     17
    80.20550609     13.09469998     08-Mar-10 20:48:24     18
    80.20550609     13.09469998     08-Mar-10 20:53:22     19
    80.20550609     13.09469998     08-Mar-10 20:58:24     20
    >
    from this output i need to filter out CONSECUTIVE unique x and y values. and the output has to be like
    >
    80.20550609     13.09469998     08-03-10 19:23     1
    80.20087123     13.09437811     08-03-10 19:33     3
    80.20550609     13.09469998     08-03-10 19:48     6
    80.20087123     13.09437811     08-03-10 19:53     7
    80.20550609     13.09469998     08-03-10 20:03     9
    80.20087123     13.09437811     08-03-10 20:08     10
    80.20550609     13.09469998     08-03-10 20:13     11
    80.20087123     13.09437811     08-03-10 20:18     12
    80.20550609     13.09469998     08-03-10 20:58     20
    >
    how to go about this requirement?
    Edited by: Aemunathan on Mar 9, 2010 5:45 PM

    The following gives the same results on your test data but maybe it's more accurate because searches both for changes in x and in y:
    SQL> with mytab as (
      2  select 80.20550609 x, 13.09469998 y, '08-Mar-10 19:23:23' mydate, 1 rn from dual union
      3  select 80.20550609,13.09469998, '08-Mar-10 19:28:37', 2 from dual union
      4  select 80.20087123,13.09437811, '08-Mar-10 19:33:25', 3 from dual union
      5  select 80.20550609,13.09469998, '08-Mar-10 19:38:24', 4 from dual union
      6  select 80.20550609,13.09469998, '08-Mar-10 19:43:25', 5 from dual union
      7  select 80.20550609, 13.09469998, '08-Mar-10 19:48:25', 6 from dual union
      8  select 80.20087123, 13.09437811, '08-Mar-10 19:53:25', 7 from dual union
      9  select 80.20087123, 13.09437811, '08-Mar-10 19:58:24', 8 from dual union
    10  select 80.20550609, 13.09469998, '08-Mar-10 20:03:25', 9 from dual union
    11  select 80.20087123, 13.09437811, '08-Mar-10 20:08:24', 10 from dual union
    12  select 80.20550609,13.09469998, '08-Mar-10 20:13:24', 11 from dual union
    13  select 80.20087123, 13.09437811, '08-Mar-10 20:18:37', 12 from dual union
    14  select 80.20550609, 13.09469998, '08-Mar-10 20:23:32', 13 from dual union
    15  select 80.20550609, 13.09469998, '08-Mar-10 20:28:25', 14 from dual union
    16  select 80.20550609, 13.09469998, '08-Mar-10 20:33:23', 15 from dual union
    17  select 80.20550609, 13.09469998, '08-Mar-10 20:38:24', 16 from dual union
    18  select 80.20550609, 13.09469998, '08-Mar-10 20:43:24', 17 from dual union
    19  select 80.20550609, 13.09469998, '08-Mar-10 20:48:24', 18 from dual union
    20  select 80.20550609, 13.09469998, '08-Mar-10 20:53:22', 19 from dual union
    21  select 80.20550609, 13.09469998, '08-Mar-10 20:58:24', 20 from dual
    22  )
    23  select x, y, mydate, rn from (
    24  select x, y, mydate, rn, nvl(lead(x) over (order by rn),0) next_x
    25         , nvl(lead(y) over (order by rn),0) next_y
    26  from mytab
    27  ) where next_x != x or next_y != y;
                       X                    Y MYDATE                               RN
             80.20550609          13.09469998 08-Mar-10 19:28:37                    2
             80.20087123          13.09437811 08-Mar-10 19:33:25                    3
             80.20550609          13.09469998 08-Mar-10 19:48:25                    6
             80.20087123          13.09437811 08-Mar-10 19:58:24                    8
             80.20550609          13.09469998 08-Mar-10 20:03:25                    9
             80.20087123          13.09437811 08-Mar-10 20:08:24                   10
             80.20550609          13.09469998 08-Mar-10 20:13:24                   11
             80.20087123          13.09437811 08-Mar-10 20:18:37                   12
             80.20550609          13.09469998 08-Mar-10 20:58:24                   20
    9 rows selected.Max
    http://oracleitalia.wordpress.com

  • Choosing a value based on newest date, and newest value

    Good Afternoon,
    I'm in search of help on a statement Im trying to perform in a Query transform in my ETL. So this is the scenario. I have a Value called SGSGVL which is "CYW" and in our descriptions table for the VALUE CYW we have 3 different Descriptions like Cadium Yellow, Cadium Yellow Paint and CDM Yellow and the date the description was added. What I would like to do is say:
    Where in the description table = CYW, select the newest date and the most used value.
    I've been told I can use a MAX statement but Im unsure exactly how to perform this in the query transform. Can anyone help? It would be GREATLY appreciated!
    Thanks!

    You won't be able to do what you are asking in one query transform - it is complicated due the fact that you need your "max" to be based on something other than the column you want returned (date and count, versus the description). Essentially, what you need to do is:
    QUERY1: value, description, field named REC_CNT with mapping of count(*), field named MAX_DATE with mapping of max(date), group by value and description
    QUERY2: reads from QUERY1 --> value, field named MAX_REC which has a mapping such as: max(lpad(REC_CNT,'0',5) || '_' || to_char(date,'YYYYMMDD')), and group by value only
    QUERY3: also reads from QUERY1 --> value, description, field named THIS_REC which has mapping such as: lpad(REC_CNT,'0',5) || '_' || to_char(date,'YYYYMMDD'), no group-by
    QUERY4: joins QUERY2 and QUERY3 on QUERY2.MAX_REC = QUERY3.THIS_REC. Pull the value and description from QUERY3.
    Basically - QUERY2 gives you the list of records which are considered the max, and QUERY3 gives you the full list with the same column to be able to join on, so QUERY4 pulls the descriptions only for the max record.
    -Trevor

  • Updating multiple records based on process date

    Hello,
    I need to change the value of multiple records in one table if a condition is met for each record in another table when the application is run.
    I have an Employee table containing employee names that also has a status field where the values are either "Active" or "Disabled".
    There is a form in the application with an employee name select list using a dynamic LOV based on the Employee table. The LOV is restricted to "Active" employees. The form inserts employee-related transactions with the current date into the Transaction table.
    I want to automatically update the status of all employees in the Employee table from "Active" to "Disabled" where there have been no transactions in the Transaction table for that employee for more than 2 months. This will allow me to exclude them from the dynamic LOV based on the Employee table.
    Any suggestions are greatly appreciated.
    Thank you,
    Matt

    Hi Matt
    Something like this?
    UPDATE employees
    SET status = 'Disabled'
    WHERE status = 'Active'
    AND NOT EXISTS(SELECT 'X'
                                      FROM transactions
                                      WHERE emp_id = trn_emp_id
                                     AND tran_date >= SYSDATE - INTERVAL '60' DAY);Let me know if I've misunderstood...
    Cheers
    Ben

  • Select distinct rows based on latest date

    Hi
    I need to produce data from two tables and return results where only data for the latest OriginationDate is returned  for each unique client. I have been trying all sorts of combinations but with no success. Any help would be appreciated
    e.g
    select
    c.client_no
    ,c.forename
    ,c.surname
    ,c.tel_no1
    ,c.tel_no2
    ,c.tel_no3
    ,o.ordernumber
    ,o.propertyidentifier
    ,o.contractorlongname
    ,o.OrderStatus
    ,o.CancelReasonDesc
    ,o.OriginationDate
    ,o.Completed
    ,DATEDIFF(d,o.OriginationDate,GETDATE())
    as Total
    FROM
    hgmclent AS c
    LEFT
    OUTER
    JOIN QLHPM_Order_Summary
    AS o
    ON
    c.client_no
    = o.ClientNumber
    WHERE
    o.Ordernumber
    IS
    NOT
    NULL
    GROUP
    BY c.client_no
    ,c.forename
    ,c.surname
    ,c.tel_no1
    ,c.tel_no2
    ,c.tel_no3
    ,o.ordernumber
    ,o.propertyidentifier
    ,o.contractorlongname
    ,o.OrderStatus
    ,o.CancelReasonDesc
    ,o.OriginationDate
    ,o.Completed
    Currently this produces the following data from which I have hidden sensitive information. What I need to show for client_no 1 is repair order 6353 which was reported on 2015-01-06 00:00:00.000 being the most recent of 12 orders for this client,
    Client No2 only has one order so this will be shown
    Client No3 should only show order number 6842 reported on 2015-01-19 00:00:00.000
    and so on.
    Can anyone help with this
    Thanks
    John

    I think he needs to return the data for the latest OriginationDate, so ORDER BY o.Completed DESC should be changed to
    ORDER BY o.OriginationDate DESC
    Row_number() Over(Partition
    by c.client_no Order
    by  o.OriginationDate
    DESC ) rn
    A Fan of SSIS, SSRS and SSAS

  • Selection of records based on minimum date actioned

    Post Author: jrdoyle
    CA Forum: Data Connectivity and SQL
    Hi!
    I've been building a report that displays records, grouped by the Service Department  to which they have been assigned; however I need to constrain the report to only show the Service Department to which the record was first assigned.  I had tried to group the report by incident reference #, and had in the details the actions taken agains the record, the date of the action, the SVD to which it was assigned, etc.  In the Select Expert, I have the following:
    {INC_DATA.EVENT_TYPE} = "i" and{SERV_DEPT.SERV_DEPT_SC} = "DISPATCH" and{INCIDENT.DATE_LOGGED} in DateTime (2007, 05, 01, 00, 00, 00) to DateTime (2007, 05, 30, 00, 00, 00) and{SERV_DEPT_1.SERV_DEPT_SC} in &#91;"CUSTHOME", "CUSTWEST", "HARDWARE"&#93;
    The SERV_DEPT_1 table will displays the information about the Service Department to which the records are assigned.  I need to be able to count only the minimum date of assignment.  I've tried using the Minimum function, but it appears that I then can't summarize (count records) higher up in the report groups, as it gets evaluated after (?) the groups are made.
    Is anyone able to offer suggestions as to how I might go about this?  I have tried to somehow flag records in the details which meet the criteria, but haven't been able to come up with anything yet.
    Thanks!

    Post Author: Jagan
    CA Forum: Data Connectivity and SQL
    I'm not quite sure how/where you tried to use the Minimum function - sounds like you used it in the record selection formula? Anyway, if you want the report to have only the earliest record per service department group then you can use the group selection expert, e.g.{incident.date_logged} = minimum({incident.date_logged}, {serv_dept_1.serv_dept_sc})If you want to display the earliest record but still have the other records there for processing then sort on {incident.date_logged} ascending, suppress the details, and print in the {serv_dept_1.serv_dept_sc} group header. i.e the record you're "looking" at in the group header is the first one for the group.The difference between the two is that the former will only have one record per service department group (assuming the date_logged is unique per incident per department) while the latter will have all records but only display one. This makes a difference when using the built-in summary functions.

  • Retriev Top to columns of table based on latest date

    Hi all,
    I have the below table
    Date                 
    Value
    1/1/2012            1000
    1/1/2013            2000 
    1/1/2014            3000
    I need a querry which will fetch the latest two dates and values. ie it should retrieve as below
    Date                  
    Value
    1/1/2013            2000 
    1/1/2014            3000
    Thanks in advance.

    SELECT TOP 2 * FROM tbl ORDER BY Date DESC
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Select records based on max(date)

    Hi everyone,
    I have a table (tbl_training) with training information-such as who took what training, when they took it, scores they received and other various stuff.
    In this table, a person could have taken multiple training within the year. what i need to see in my results is, the last training the person took. I assume i am looking to query something that produces max(date_of_training) and maybe grouping my id_number. I have tried various combinations of sub-queries to no avail. Any help is welcomed.
    So my data may look something like this:
    id_number date_of_training score last_name first_name instructor rank
    1234 01/01/09 50 doe john mr. hank sgt
    1234 02/13/09 72 doe john mr. hank sgt
    1234 01/31/09 60 doe john mr. hank sgt
    5678 02/03/09 80 smith lisa mr. hank cpl
    What i need returned in the query is:
    1234 02/13/09 72 doe john mr. hank sgt
    5678 02/03/09 80 smith lisa mr. hank cpl
    Select id_number, date_of_training, score, last_name, first_name, instructor, rank
    from tbl_training;
    Thanks for the help in advance.

    Try this code
    select * from (
    Select id_number, date_of_training, score, last_name, first_name, instructor, rank, row_number()over(partition by id_number order by date_of_training desc ) rn
    from tbl_training)
    where rn =1;

  • Sort all the Records in Data manager based on Update Date

    How to sort the reocrds in Data Manager based on Date or something ?
    And also I have three records for a same customer in ( for three different company codes ) and when I search for this customer with the Customer number then it is showing three records , but when I search with Update Date then no records are fetched ...what is the reason ?

    If you make a field as type "Time Stamp" in your data model using the MDM Console, make sure that the option Sort Index is set to Normal.  If this is the case, whenever a record is updated in the repository, the date will be updated.  If the sort index is normal, then MDM will allow you to sort the records based on the date and time by which they were updated.  You can do this by finding your time stamp field in the MDM data manager and clicking on it.  If there is an up and down arrow next to the name of your field, it means it can be sorted.  Also, to answer your other question, you can definitely search based on date.  Use the Free-Form Search on the left hand side of the data manager at the bottom of the screen.  Simply select a date, and it will show you all the records updated on that date.

Maybe you are looking for