----------------------怎找出同一中最近一的用和以前用不同的
容用
CZZ-07040331.xxx111252372007/4/8 19:49
CZZ-07040331.xxyy111252372007/4/9 19:50
CZZ-07040331,yyyy111252372007/4/10 19:50
CZZ-07040331.zzzzz111228452007/4/11 19:49
CZZ-0704034.....
怎找出同一中最近一的用和以前用不同的,如上面的CZZ-07040332007/4/11 19:49的用11122845就一的其它用不相同,怎查找出。
!
[解决办法]
select distinct ,用 from tb1 order by
[解决办法]
你是不是想找出一个编号,不同用户最后一次的记录呀,
可以这样
select * from 表 a
where not exists (select 1 from 表 where =a. and 用=a.用 and > a.)
[解决办法]
--最近
select ,max() as from T group by
"和以前用不同的 ",理解有吃力
[解决办法]
--try看:
select A.*
from T A
inner join
(select ,max() as from T
where (select count(distinct c.用) from T c where c.=T.) > 1
group by ) B
on A.=B. and A.=B.
[解决办法]
--创建测试环境
create table test
(
编号 varchar(30),
内容 varchar(30),
用户 varchar(30),
时间 datetime
)
insert into test select 'CZZ-0704033 ', '1.xxx ', '11125237 ', '2007/4/8 19:49 '
union all select 'CZZ-0704033 ', '1.xxyy ', '11125237 ', '2007/4/9 19:50 '
union all select 'CZZ-0704033 ', '1,yyyy ', '11125237 ', '2007/4/10 19:50 '
union all select 'CZZ-0704033 ', '1.zzzzz ', '11122845 ', '2007/4/11 19:49 '
union all select 'CZZ-0704034 ', '1.xxyy ', '11125239 ', '2007/4/9 19:50 '
union all select 'CZZ-0704034 ', '1,yyyy ', '11125239 ', '2007/4/10 19:50 '
--解决方法
select * from test a
where not exists(select 1 from test b where a.编号=b.编号 and a.时间 <b.时间)
and not exists(select 1 from (select * from test a
where not exists(select 1 from test b where a.编号=b.编号 and a.时间> b.时间)
) c where c.编号=a.编号 and c.用户=a.用户 )