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
Post a Comment