一条超难解决的sql语句
我有一张表里面有很多箱号的记录,每个不同的箱号分别都有多条记录,每条记录都有不同的更新时间,我怎么才能取出每个箱号最后一条更新的记录? 问题点数:100、回复次数:6Top
1 楼tangqijun199(撒旦.冲上了5角还差一个猩猩,继续努力……)回复于 2005-08-04 14:42:25 得分 0
select * from
t1 a,
(select 箱号,max(时间) as 时间 from t1 group by 箱号) b
where a.箱号=b.箱号 and a.时间=b.时间Top
2 楼coolingpipe(冷箫轻笛)回复于 2005-08-04 14:51:32 得分 0
select *
from t1 inner join (select 箱号,max(时间) as 时间 from t1 group by 箱号) t2
on t1.箱号=t2.箱号 and t1.时间=t2.时间
Top
3 楼coolingpipe(冷箫轻笛)回复于 2005-08-04 14:52:09 得分 0
select *
from t1 inner join (select 箱号,max(时间) as 时间 from t1 group by 箱号) t2
on t1.箱号=t2.箱号 and t1.时间=t2.时间
Top
4 楼phantomMan()回复于 2005-08-04 14:58:11 得分 0
create table a(
箱号 varchar(10),
更新时间 datetime
)
insert into a values('001','2005-05-06')
insert into a values('001','2005-05-05')
insert into a values('001','2005-05-07')
insert into a values('002','2005-05-05')
insert into a values('002','2005-05-08')
insert into a values('002','2005-05-09')
insert into a values('003','2005-05-02')
insert into a values('003','2005-05-05')
select t1.* from a t1
where exists(
select 1 from a t2
where t1.箱号=t2.箱号
having max(t2.更新时间)=t1.更新时间
)Top
5 楼geniusqing(依帆)回复于 2005-08-04 14:58:40 得分 0
select a.箱号,b.时间 from t1 a,
(select 箱号,max(时间) as 时间 from t1 group by 箱号) b
where a.箱号=b.箱号 and a.时间=b.时间
Top
6 楼libin_ftsafe(子陌红尘:TS for Banking Card)回复于 2005-08-04 15:25:47 得分 0
select
a.*
from
表 a
where
not exists(select 1 from 表 where 箱号=a.箱号 and 时间>a.时间)Top




