日期:2014-05-18  浏览次数:20556 次

数据库查询的问题,急!!!再线等
有两个表,表1主键为客户编号,表2用客户编号与表1关联,不过表2中有客户编号重复的记录,这些记录的创建时间不同,我想查询出表1与表2中编号相同且表2中该编号记录创建最晚的数据,要怎么处理,SQL   Server里有什么好的处理机制吗

------解决方案--------------------
select a.客户编号,b.* from
表1 a,表2 b
where a.客户编号=b.客户编号 and b.时间=(select max(时间) from 表2 where 客户编号=a.客户编号)
------解决方案--------------------
select * from a where exists(select * from b where 时间 in (select max(时间) from b
group by 客户编号)