易截截图软件、单文件、免安装、纯绿色、仅160KB

这个表的SQL语句

表内容 :
张三 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)

引用
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)

----------------


相关问答:

jsp链接sql2000的疑问?



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

sql性能求助 - MS-SQL Server / 疑难问题

场景如下:
客户把备份好的数据库,发给我,我在本机还原后,运行写好的存储过程,比较快,并且在实施那边运行同样比较快。但是当实施在客户那边运行的时候速度就非常的慢,时间超出了程序的时间限制。远程在客户那 ......

求一sql【谢谢】 - MS-SQL Server / 基础类

需求如下:
a表:
 p_id status  
  1 0
  2 0
b表
rec_id pid purchase_qty receive_qty flag
1 1 10 10 0
2 ......

一条sql查询语句

题目:把“SC”表中“叶平”老师教的课的成绩都更改为此课程的平均成绩; 
sql语句:
  update SC set score=(SELECT avg(SC_2.score)  
  from SC SC_2  
  WHERE S ......

SQL时间段问题

一个很奇怪的问题 
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'
--一条数据 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号