datetime - SQL get the last date time record -


i'm trying last datetime record table happens store multiple status. table looks so:

+---------+------------------------+-------+ |filename |dates                   |status | +---------+------------------------+-------+ |abc.txt  |2012-02-14 12:04:45.397 |open   | |abc.txt  |2012-02-14 12:14:20.997 |closed | |abc.txt  |2013-02-14 12:20:59.407 |open   | |dfg.txt  |2012-02-14 12:14:20.997 |closed | |dfg.txt  |2013-02-14 12:20:59.407 |open   | +---------+------------------------+-------+ 

the results should

+---------+------------------------+-------+ |filename |dates                   |status | +---------+------------------------+-------+ |abc.txt  |2013-02-14 12:20:59.407 |open   | |dfg.txt  |2013-02-14 12:20:59.407 |open   | +---------+------------------------+-------+ 

if want 1 row each filename, reflecting specific states , listing recent date friend:

select filename ,        status   ,        max_date = max( dates ) some_table t group filename , status having status = '<your-desired-status-here>' 

easy!


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -