query max and min with two situation, same and different date

Discussion in 'Database' started by newphpcoder, Dec 19, 2011.

  1. newphpcoder

    newphpcoder New Member

    Joined:
    Sep 24, 2010
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Web Programmer
    Location:
    Philippines
    Hi..

    I know its a couple of weeks that i have problem in datetime..
    For example i have this data:
    00100 2011-11-20 05:35:00
    00100 2011-11-20 13:35:00
    00100 2011-11-21 21:35:00
    00100 2011-11-22 05:35:00
    when I tried this query for testing:
    Code:
    SELECT a.EMP_NO, max(a.DTR), min(b.DTR) FROM regular_dtr a LEFT JOIN regular_dtr b ON a.EMP_NO = b.EMP_NO;
    
    i have this output:
    EMP_NO--max_dtr------------------min_dtr
    00100----2011-11-22 05:35:00-----2011-11-20 05:35:00
    i need result is:
    EMP_NO--max_dtr------------------min_dtr
    00100----2011-11-20 13:35:00-----2011-11-20 05:35:00
    00100----2011-11-22 05:35:00-----2011-11-21 21:35:00
    I really, don't know what syntax should i need..
    I'm sorry if until now, I did not solve this:(
    Any help is highly appreciated..
    Thank you so much...i hope you would not angry with me...the reason why i post again this problem because now i only have two columns, EMP_NO and DTR(IN and OUT) and i have no right to demand to separate the data of in and out...so that in my part I need to do that but sad to say, I have only few knowledge in mysql..specially in functions.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice