疑难问题,请大家帮忙!

thanmail 2006-03-13 10:16:47
有表如下:

组名 得分 时间
team1 99 2005.1.1
team1 92 2005.2.5
team1 95 2006.1.3
team2 91 2005.3.2
team2 98 2005.6.5
team2 96 2006.3.2

要求最新时间的各组的得分情况:
即得到下表:
team1 95 2006.1.3
team2 96 2006.3.2

分不够可以再加!
...全文
90 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
thanmail 2006-03-14
  • 打赏
  • 举报
回复
谢谢大家!
thanmail 2006-03-14
  • 打赏
  • 举报
回复
从现在起,如果有新的方法请发帖,
老的方法就不再给分了,
新方法我再加分。
wgsasd311 2006-03-14
  • 打赏
  • 举报
回复
create table tb(组名 varchar(10), 得分 int , 时间 datetime)
insert into tb
select 'team1', 99 , '2005.1.1'
union select 'team1', 92, '2005.2.5'
union select 'team1', 95, '2006.1.3'
union select 'team2', 91, '2005.3.2'
union select 'team2', 98, '2005.6.5'
union select 'team2', 96, '2006.3.2'

go
select * from tb a
where
not exists(select 1 from tb where a.组名=组名 and 时间>a.时间)

drop table tb
$扫地僧$ 2006-03-14
  • 打赏
  • 举报
回复
create table fen(组名 varchar(10), 得分 int , 时间 datetime)
insert into fen
select 'team1', 99 , '2005.1.1'
union select 'team1', 92, '2005.2.5'
union select 'team1', 95, '2006.1.3'
union select 'team2', 91, '2005.3.2'
union select 'team2', 98, '2005.6.5'
union select 'team2', 96, '2006.3.2'


select * from fen a where 时间=(select top 1 时间 from fen where 组名=a.组名 order by 时间 DESC)
yuweiwei 2006-03-14
  • 打赏
  • 举报
回复

create table fen(组名 varchar(10), 得分 int , 时间 datetime)
insert into fen
select 'team1', 99 , '2005.1.1'
union select 'team1', 92, '2005.2.5'
union select 'team1', 95, '2006.1.3'
union select 'team2', 91, '2005.3.2'
union select 'team2', 98, '2005.6.5'
union select 'team2', 96, '2006.3.2'

select 组名,Max( 时间)shijian from fen group by 组名
select fen.* from fen,(select 组名,Max( 时间)shijian from fen group by 组名)tt
where fen.组名=tt.组名 and fen.时间=tt.shijian
huailairen 2006-03-13
  • 打赏
  • 举报
回复
结果
组名 得分 时间
---------- ----------- ------------------------------------------------------
team1 95 2006-01-03 00:00:00.000
team2 96 2006-03-02 00:00:00.000

(所影响的行数为 2 行)

huailairen 2006-03-13
  • 打赏
  • 举报
回复

create table fen(组名 varchar(10), 得分 int , 时间 datetime)
insert into fen
select 'team1', 99 , '2005.1.1'
union select 'team1', 92, '2005.2.5'
union select 'team1', 95, '2006.1.3'
union select 'team2', 91, '2005.3.2'
union select 'team2', 98, '2005.6.5'
union select 'team2', 96, '2006.3.2'

select * from fen

select *
from fen a
where not exists(select * from fen b where a.组名=b.组名 and a.时间<b.时间)

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧