- 論壇徽章:
- 0
|
嗯,看看這樣行了吧? 自己感覺效率有點(diǎn)低,呵呵,等待版內(nèi)各高手的答案
create table chk(
user varchar(8) not null,
ip char(15) not null
);
create table act(
user varchar(8) not null,
sttid char(15) not null,
time int not null
);
insert into act values
('tom','1.1.1.1',1),
('tom','1.1.1.6',2),
('tom','1.1.1.9',4),
('James','1.1.1.2',1),
('Peter','1.1.1.3',1),
('Joe','1.1.1.4',1);
insert into chk values
('tom',''),
('James',''),
('Peter',''),
('Robot','');
select * from act
where (user,time) in
(select user,max(time) from act group by user);
-- 這樣select的話,保證選出來的子集都是“時(shí)間最大的用戶紀(jì)錄”
update chk as x
set ip=(select sttid from act as y
where x.user=y.user and (user,time) in
(select user,max(time) from act group by user)
)
where x.user in (select user from act);
|
還有,沒有用樓主的命名實(shí)例,是為了少敲點(diǎn)鍵盤,就麻煩樓主自己改一改語句吧
[ 本帖最后由 fnems 于 2007-7-17 15:35 編輯 ] |
|