To retrieve the Maximum Date from the record

Hi All,
I am using the bleow query to retrieve the max date from the record list:
select w.wr_no,w.customer_id,w.place_id, w.entry_Date, max(app.appointment_date) as appointment_date
from work_request w , wr_appointment app
where w.wr_no=app.wr_no
and w.customer_id = '020167001'
and w.place_id = '1151667'
group by w.wr_no, w.customer_id,w.place_id, w.entry_Date;
However i am getting the as many as three rows even after using the max function. The max date comes as the last record out the three rows retrieved.
Thanks,
Mark

Mark Andrew wrote:
And for Sven for the above customer id and place id, i receive the below result:
WR_NO CUSTOMER_ID PLACE_ID ENTRY_DATE APPOINTMENT_DATE
1306782233 020167001 1151667 26/07/2010 29/07/2010
1387090103 020167001 1151667 26/02/2010 16/03/2010
1393896673 020167001 1151667 23/01/2011 25/01/2011
After using the rank function i will be receiving:
WR_NO CUSTOMER_ID PLACE_ID ENTRY_DATE APPOINTMENT_DATE RK
1393896673 020167001 1151667 23/01/2011 25/01/2011 1Now I get it.
In fact you want to group only on the customer (and place_id?) and get all the information from the line with the last appointment date.
Analytic functions such as RANK or ROW_NUMBER are good for this.
The select can look like this.
select * from (
   select w.wr_no,w.customer_id,w.place_id, w.entry_Date, app.appointment_date,
         row_number() over (partition by w.customer_id, w.place_id order by  app.appointment_date desc,  w.wr_no desc) rn
   from work_request w , wr_appointment app
  where w.wr_no=app.wr_no
  --and w.customer_id = '020167001'
  --and w.place_id = '1151667'
where rn = 1
;In fact I think you can do the same operation in EXCEL directly.
FIrst you need to sort the data by customer (asc), place (asc) and appointment date (desc).
Then add a column in excel that give you the line where you have a new customer id.
Assuming this new column is column H and the customerid is in column A then the function in Cell H2 would look like this.
A function like ("=A2=A1"). Copy this formular to all the other H cells.
Then add a auto filter on it and only select all the rows where the result is FALSE.
Same logic as in SQL, but done in Excel.

Similar Messages

  • Retrieve the records based on date where date is not stored

    Hi,
    I have one table in Oracle.
    I want to retrieve the records which are added or modified after a particular date & time.(but the table does not contain any column for date & time )
    For example: Product table(pid number,pname varchar2)
    i am entering 10 records on date 21/07/2005
    i am entering 20 records on date 22/07/2005
    i am entering 15 records on date 23/07/2005
    i am entering 30 records on date 24/07/2005
    If i want to retrieve the records added after 22/7/2005
    (ie.) last 45 records
    But the table does not contain any date field.
    How will you know date & time of each record updated in the table.
    If any one knows, help me.
    bye.

    for 9iR2: check out online document of Oracle9i Application Developer's Guide - Fundamentals and search flash back query
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96590/adg08sql.htm#10851
    for 10G, flash back feature is enhenced to whole database level, you can still use flash back query though.

  • The logic board on my MacBook Pro has failed. How do I retrieve all my data from the hard drive?

    The logic board on my MacBook Pro has failed. How do I retrieve all my data from the hard drive?

    Remove the drive and put it in an external enclosure. Backup the drive completely. Repartition and format the drive. Replace the drive into the computer. Take the computer in for the logicboard replacement.

  • Query to retrieve the records which have more than one assignment_id

    Hello,
    I am trying to write a query to retrieve all the records from the table per_all_assignments_f which has more than one different assignment_id for each person_id. Below is the query i have written but this retrieves the records even if a person_id has duplicate assignment_id's but i need records which have more than one assignement_id with no duplicates for each person_id
    select assignment_id ,person_id, assignment_id
    From per_all_assignments_f
    having count(assignment_id) >1
    group by person_id, assignment_id
    Thank You.
    PK

    Maybe something like this?
    select *
    From   per_all_assignments_f f1
    where  exists (select 1
                   from   per_all_assignments_f f2
                   where  f2.person_id = f1.person_id
                   and    f2.assignment_id != f1.assignment_id
                  );Edited by: SomeoneElse on May 7, 2010 2:23 PM
    (you can add a DISTINCT to the outer query if you need to)

  • Retrieving Chrome Library data from Time Machine?

    How can I Retrieve Chrome Library data from Time Machine? It seems no Library data has been backed up.  Any ideas why not and How I can get the hidden library to be backed up in the future and have access to it in Time Machine?

    We might help you better if you possibly knew what you were talking about. OS X only hides the user's /Home/Library/ folder. Only the Chrome developers know where they would be hiding a Chrome library, if there is such an animal.
    If you want to find the /Home/Library/ folder:
    Exposing the /Home/Library/ Folder
    Pick one of the following methods:
    A. This method will make the folder visible permanently. Open the Terminal application in your Utilities folder and paste the following at the command prompt:
    chflags nohidden ~/Library
    Press RETURN.
    B. Click on the Desktop, press the OPTION (⌥) button, select Library from the Finder's Go menu.
    C. Select Go To Folder from the Finder's Go menu. Paste the following in the path field:
    ~/Library
    Press the Go button.

  • Transfer data from one record typr to other

    Hi All,
    How can we move data from one record type to other record type in Oracle PL/SQL?
    Can any one reply me ASAP.
    Thanks in Advance,
    Dhana

    Like this
    declare
      type rec is record(no integer, name varchar2(10));
      rec1 rec;
      rec2 rec;
      rec3 rec;
    begin
      rec1.no := 1;
      rec1.name := 'karthick';
      dbms_output.put_line(rec1.no||'/'||rec1.name);
      --Now just assign rec1 to the rec2 by element
      rec2.no := rec1.no;
      rec2.name := rec1.name;
      dbms_output.put_line(rec2.no||'/'||rec2.name);
      --Now just asign directly
      rec3 := rec2;
      dbms_output.put_line(rec3.no||'/'||rec3.name);
    end;

  • HT201263 I would like retrieve all my data from my IPhone 4S after I lost all my data! Please help! ? Thank You.

    I would like retrieve all my data from my IPhone 4S after I lost all my data due constant Apple logo on! After I restored this phone I lost all my contacts, text messages, pictures, videos..!!! The question I have is if I never backed up to iCloud and iTunes is there any way I can retrieve all my data that was before restoring this iPhone 4S. Please help! ? I greatly appreciated !!!

    If you never synced your phone to your computer and your contacts were not synced to iCloud or another cloud-based service, everything is gone. You will have to start fro scratch.
    ~Lyssa

  • HOW to retrieve PURCHASE ORDER DATA from archieve file and print a report

    Dear all
    1) I have retrieve purchase order data from archived files.
    2)  print purchase order data and created pdf file.
    VIJ.............
    Moderator message - Please ask a specific question - post locked
    Edited by: Rob Burbank on Apr 28, 2009 12:00 PM

    Dear all
    1) I have retrieve purchase order data from archived files.
    2)  print purchase order data and created pdf file.
    VIJ.............
    Moderator message - Please ask a specific question - post locked
    Edited by: Rob Burbank on Apr 28, 2009 12:00 PM

  • SQL  to retrieve the records in subset

    Dear Friends,
    I have requirement to fetch 5 Million records from Oracle db and display using JAVA and JSP. Each record is 1 KB size.
    The database table is online table used to store the transaction details, the rows will keep increasing. I am not allowed to use stored procedures also.
    1) Fetching 5 Million record and displaying in 1 attempt is not feasible as JDBC has limitation and also the User has to wait too long to see the data.
    I am thinking of processing the records in subset, for example.. Display first 10000 records then if the users wants next 10000 records fetch and display the next 10000 record.
    Are there any other best practices to implement the above requirement.
    I am not sure how to write the above SQL query? Can anyone please help me write the above SQL query?
    I dont this I can use romnum as the rows are increasing.
    Below is my Table structure and SQL query which returns 5 Million record
    CREATE TABLE MESSAGE_LOG
    SOURCE VARCHAR2(25 BYTE),
    TARGET VARCHAR2(25 BYTE),
    ENGINE VARCHAR2(100 BYTE),
    PROCESS VARCHAR2(400 BYTE),
    SERVICE VARCHAR2(100 BYTE),
    LOGTIMESTAMP TIMESTAMP(6)
    SELECT * FROM MESSAGE_LOG WHERE LOGTIMESTAMP BETWEEN TO_DATE('20-MAY-2010 01:00','DD-MON-YYYY HH24:MI') AND TO_DATE('20-MAY-2010 23:00','DD-MON-YYYY HH24:MI')
    Thanks in advance,
    Bob

    user13109986 wrote:
    I have requirement to fetch 5 Million records from Oracle db and display using JAVA and JSP. Why no one will look at five million results. And even if they wanted to it would take longer than the average human lifetime.
    I am not allowed to use stored procedures also.Why, is there a business requirement that says the application should be as difficult to develop as possible, be unreliable and hard to maintain when things go wrong?
    >
    1) Fetching 5 Million record and displaying in 1 attempt is not feasible as JDBC has limitation and also the User has to wait too long to see the data.As the user will never read five million results, it doesn't matter
    Try this link and come back when you have got to the 5,000,000 result of the 6,730,000 that are estimated to be there
    http://www.google.com/#hl=en&q=oracle+procedure
    Or you could list every thread in the forum and multiply the time it takes you to get to the last by 50.
    I am thinking of processing the records in subset, for example.. Display first 10000 records then if the users wants next 10000 records fetch and display the next 10000 record.Try looking at 10,000 threads on this forum or 10,000 results from Google and see how long that takes.
    Are there any other best practices to implement the above requirement.Yes, don't return more information than anyone could possibly find useful

  • SQL Query to retrieve the records

    Hi All,
    I have one table. It contains millions of records.I gave the query as follows.
    select * from emp where empnob in (1,1000)
    it displays empnob
    1 A 300000 Manager
    6 B 120000 Analyst
    87 C 32980 salsman
    Now I want to retrieve remaining records. Pelase let me know the query which are not available in emp table between the given limit.
    Thank you.

    Hi ,
    For example there are 10 records only.
    I gave
    select * from emp where empno in (1,10)
    t displays the records having the empnos 1,3,4,6,8
    Now I want to display the records 2,5,7,9,10 also...
    Please let me know the query.Are use using an oracle database? My Oracle database would never return such a result for your query.
    Please post some output from an sqlplus session where you show us exactly what you do.
    Message was edited by:
    Sven W.

  • Retrieve data from different record

    I want to display a characteristic from a previous record, from the same cube, but display it in the current record row.
    i.e. get the most recent activity of type"XX" and display the result characteristic from that record on the most recent "YY" activity record.
    Hope this makes sense.
    Is the only way to do this in a Virtual Key figure?
    Thanks

    Solved problem, posting this incase others have problem
    I solved this problem by using an Infoset. To get the most recent record I used the TOP N (1) in a condition on a RKF.

  • Help ! Cannot retrieve Object table data from Oracle 8i

    Dear All,
    Created the object and object table in SQL*Plus. If query from SQL*Plus, return rows selected.
    But if query from SQL*Plus worksheet and ODBC Test program, return "0 rows selected".
    Similary, if created the object and object table in SQL*Plus worksheet and query from SQL*Plus worksheet, return rows selected.
    But if query from SQL*Plus or ODBC Test program, return "0 rows selected".
    Appreciate advice from anyone. Thanks in advance.
    Oracle version. 8i Enterprise Edition Release 2
    Scrip to create object and insert record:
    CREATE TYPE stockitem_objtyp AS OBJECT (
    STOCKNO NUMBER,
    PRICE NUMBER,
    TAXRATE NUMBER
    CREATE TABLE stock_objtab of stockitem_objtyp (stockno primary key) object id primary key;
    INSERT INTO Stock_objtab VALUES (1, 1000, 3);
    select * from stock_objtab;
    null

    First, I suspect that this question probably belongs on the ODBC forum, since it doesn't appear to be at all related to the JVM.
    That said, I don't seem to have any problem retrieving the data, either through ODBC or SQL*Plus. If you post your question to the ODBC forum, perhaps some other folks will be able to try this and we can narrow down the problem.
    Justin Cave
    ODBC Development

  • Retrieve specific range data from oracle table

    Hi, Dear friends,
    I want to retrieve all the data from oracle table and then save them to mysql table using JDBC ResultSet. The problem is that some oracle table is too big, if I retrieve all of them to memory at a once time using excuteQuery, the program will become no response out of memory limitation. So my question is if I can retrieve just specific range data once a time. I can¡¯t find this function through JDBC API. Also, I don¡¯t want to use the specific sql sentence, for example ¡°select ¡ from¡ where someid>¡ and someid<¡¡±, because there are many different tables, I want to transfer them automatically. So I can¡¯t construct such sql sentence in advance. Does anyone know if oracle JDBC driver provide such kind of function or does there any other way?
    Any suggestion will be greatly appreciated!
    Sammy

    Dear Justin,
    thank you so much for your prompt reply!
    as your suggestion, I do check the performance while my program is running, after the program become nearly no response, I found the memory usage is nearly 100%, while disk usage and process usage is pretty low. that's the reason why I guess maybe the memory limitation, but the strange thing is that no any error reported by JBuilder, it just nearly no response and don't transfer any data any more. my os is windows xp, the version of JBuilder is 7. my main memory is 768M. just as you said, the total 6,000 records in not very large, just no more than 400K. another strange thing is that why my program works well when there is little data records in the table.
    the big picture of my program is first I retrieve oracle table metadata, according to this information, I construct DDL sql words and then create the corresponding table in mysql database. this part works well. in order to save your time, I will not paste the code here. then there is a method to transfer oracle data to mysql table, whenever creating the mysql table, then I will call this method to transfer datat to it. the following is the code of this method, I am very sorry to take your time. please read it when you are available.
    thank you very much!!
    Sammy
    //transfer data from oracle to mysql!!!
    private static void transferData(Connection oracleConn, Connection mysqlConn, String oracleTableName, String oracleSchemaName) throws SQLException{
    Statement oracleStmt=oracleConn.createStatement();
    Statement mysqlStmt=mysqlConn.createStatement();
    // sending sql to oracle to retrieve data
    String thisTableName=oracleTableName;
    String oracleSQL="SELECT * FROM ".concat(thisTableName);
    ResultSet oracleRS = oracleStmt.executeQuery(oracleSQL);
    String sql="";
    if (oracleRS.next()) {
    ResultSetMetaData rsmd = oracleRS.getMetaData();
    int colCount = rsmd.getColumnCount();
    do {
    String sqlBodyPart="";
    String sqlValuePart="";
    System.out.println("the number of column is "+colCount);
    for (int i = 1; i <= colCount; i++) {
    String columnValue = oracleRS.getString(i);
    boolean b = oracleRS.wasNull();
    String columnName =rsmd.getColumnName(i);
    System.out.println("the value of column " + i + "is " + columnValue);
    //construc the sql body part and value part
    sqlBodyPart=sqlBodyPart.concat(" ").concat(columnName).concat(",");
    if(b){ //if the value of the column i is null
    sqlValuePart=sqlValuePart.concat(" null").concat(",");
    }else{
    sqlValuePart=sqlValuePart.concat(" '").concat(columnValue).concat("',");
    //get rid of the last comma in sqlBodyPart and sqlValuePart
    if(!sqlBodyPart.equalsIgnoreCase("")) sqlBodyPart=sqlBodyPart.substring(0,sqlBodyPart.length()-1);
    if(!sqlValuePart.equalsIgnoreCase("")) sqlValuePart=sqlValuePart.substring(0,sqlValuePart.length()-1);
    //construct the sql sentence!!!
    sql="INSERT INTO ".concat(thisTableName).concat(" (").concat(sqlBodyPart).concat(") ").concat(" VALUES(").concat(sqlValuePart).concat(")");
    System.out.println("the sql words for this column is");
    System.out.println(sql);
    System.out.println(" ");
    if(mysqlStmt!=null){
    int rows = mysqlStmt.executeUpdate(sql);
    } else{
    System.out.println("can't connect with mysql server");
    System.exit(1);
    while (oracleRS.next());
    } else {
    System.out.println("There are no data in the table...");
    }//end of method data transfer!
    //end of method data transfer!

  • How do I retrieve all my data from a slow restore process?

    Recently I traded my iPad mini in for a new one because the old one broke, and I was trying to update my new iPad with the data from my last iCloud backup on my old device. Most of the data has been restored onto my new device, but I am still missing numerous photos from my old device that were backed up. My iPad has been connected to wifi for three days now, and every time I open my photos app, I still get the "Downloading..." message at the bottom of the screen, along with numerous blank photos. How can I speed up the restore process to retrieve those photos faster? Or what else can I do to get those photos back?

    http://manuals.info.apple.com/en_US/iphone_user_guide.pdf, page 159

  • Data from Info Records

    Due to a vendor number change I need to extract data from an existing Info Record and load it again as a new Info Record. I have been looking for programs or BAPIs for doing this, but I don´t seem to find the way. Any ideas?

    There are standard LSMW routines which all you do upload.  You can extract the data from tables EINE and EINA.  You can do this via se16 or you can write a custom program to do so.  Format the data for your LSMW and upload.   You also might want to try doing mass changes via transaction MEMASSIN.
    Regards,
    Rich Heilman

Maybe you are looking for