表内容 : 张三 2009-2-11 1000.0000 李四 2009-3-11 1000.0000 王五 2009-2-10 200.0000 李四 2009-3-20 2000.0000 张三 2009-3-11 200.0000 王五 2009-3-10 200.0000 通过使用SQL语句,查处每个人最后的一条记录(日期最晚的一天记录)。 返回如下结果: 李四 2009-3-20 2000.0000 张三 2009-3-11 200.0000 王五 2009-3-10 200.0000 SQL语句怎么写 求解~谢谢 日期是Datatime 请测试后回答!!! 数据库SQL2000或者2005 就一个表 没有ID列select a.* from TB a where a.DateTime=(Select Max(b.DateTime) from TB b where a.Name=b.Name) 应该可以 顶一下 SQL code:
if object_id('[tb]') is not null drop table [tb] go create table [tb]([name] varchar(20),[time] datetime,[money] float) insert [tb] select '张三', '2009-2-11', 1000.0000 union all select '李四', '2009-3-11', 3000.0000 union all select '王五', '2009-2-10', 200.0000 union all select '李四', '2009-3-20', 2000.0000 union all select '张三', '2009-3-11', 200.0000 union all select '王五', '2009-3-10', 200.0000 go
select a.* from tb a where a.time=(Select Max(b.time) from tb b where a.Name=b.Name)
一个很奇怪的问题 SQL code select * from Gprs_DataInof --可以查到所有的数据 select * from Gprs_DataInof where DataTime between 1900-10-16 1:01:00' and '2009-10-20 1:01:00' --一条数据 ......