jjxia2001
asked on
How do I select the latest date infor for the multiple dates database
I forgot how to select the data with the latest date from a large database. Here is an example of my database:
CustomerID Timestamp Expense .....
abc 11/14/2010 3:30PM 2000.00
abc 11/15/2010 9:00AM 1500.00
abc 11/15/2010 9:15AM 1800.00
CustomerID Timestamp Expense .....
abc 11/14/2010 3:30PM 2000.00
abc 11/15/2010 9:00AM 1500.00
abc 11/15/2010 9:15AM 1800.00
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
-- from entire table
select top 1 * from tbl order by timestamp desc
-- latest for each customer
select customerid, timestamp, expense
from
(
select customerid, timestamp, expense,
rn=row_number() over (partition by customerid order by timestamp desc)
from tbl
) sq
where rn=1