1

I am trying to use Max function to get the record with latest dates but it does not give desired results as it also gives data with old dates.Below is output of dataframe OA_Output:

 Org_ID   ORG_OFFICIAL_NORM_NAME  ORG_IMMEDIATE_PARENT_SRC   ORG_IP_SRC_MD_Date 
--------  ----------------------  ------------------------   ------------------ 
 132693   BOLLE INCORPORATED          abc.com               26-JUN-18
 122789   BEE STINGER, LLC            aa.com                12-Mar-18
 344567   CALIBER COMPANY             xyz.com               16-Feb-16
 639876   Maruti                      yy.com                23-Jun-17

I am running below R Code to get the records with latest dates:

gautam1 <-

  sqldf(

    "
    SELECT ORG_OFFICIAL_NORM_NAME,ORG_IMMEDIATE_PARENT_SRC
   ,MAX(ORG_IP_SRC_MD_DATE),ROW_ID
    FROM OA_output
    where ROW_ID = 1
    and ORG_IMMEDIATE_PARENT_SRC like '%exhibit21%'
    GROUP BY ORG_IMMEDIATE_PARENT_ORGID
    ORDER BY ORG_IMMEDIATE_PARENT_ORGID

    "    )

In The above code max function is not giving desired results.I am not sure whether there is a date format issue between Oracle and R. Any help will be appreciated Thanks Gautam

1 Answers1

0

can you please use below query as a sql and run again code

  SELECT ORG_OFFICIAL_NORM_NAME,ORG_IMMEDIATE_PARENT_SRC
       ,MAX(ORG_IP_SRC_MD_DATE),ROW_ID
        FROM OA_output
        where ROW_ID = 1
        and ORG_IMMEDIATE_PARENT_SRC like '%exhibit21%'
        GROUP BY ORG_OFFICIAL_NORM_NAME,ORG_IMMEDIATE_PARENT_SRC,ROW_ID
        ORDER BY ORG_IMMEDIATE_PARENT_ORGID
Zaynul Abadin Tuhin
  • 31,407
  • 5
  • 33
  • 63
  • I need to run the above query in R to get the records with latest dates – Gautam Biswas Aug 07 '18 at 07:17
  • @GautamBiswas does this query return your expected result in db editor? if it is return your expected result in db editor then definitely it will return in R, so my idea 1st run this sql code in db then check is that correct or not? then move new strategy – Zaynul Abadin Tuhin Aug 07 '18 at 07:23