I have a table in SQL Server Compact Edition 4.0 where I would like to extract the last record entered each day for every file. So if duplicate entries are made in the same day then only choose the last one for each file.
Column Name (DATA TYPE)
For example:
TimeStamp (DATETIME) | FileName (NVARCHAR)
9/11/2013 4am | File1.txt
9/12/2013 11 PM | File1.txt
9/12/2013 11:30PM | File1.txt
9/12/2013 11:35pm | File2.txt
9/12/2013 11:36pm | File2.txt
9/13/2013 1am | File3.txt
Would return
9/11/2013 4am | File1.txt
9/12/2013 11:30PM | File1.txt
9/12/2013 11:36pm | File2.txt
9/13/2013 1am | File3.txt
Thanks in advance for any help
Try
SELECT MAX(TimeStamp) TimeStamp, FileName
FROM Table1
GROUP BY DATEPART(dd, TimeStamp), FileName
Here is SQLFIddle demo
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.