SID FY Type Series No Version 15476 2012 A 1 1 15476 2012 A 2 1 15476 2012 A 2 2 15476 2012 A 3 1 15800 2012 A 1 1 15800 2012 A 2 1 15800 2012 A 2 2 15800 2012 A 3 1
也就是说,要找出下面这样的结果记录: 15476 2012 A 3 1 15800 2012 A 3 1
不能找出 象15476,2012,A,3,2这样的结果出来。
怎么写SQL语句????
SQL SERVER 里的 [/code]
------解决方案--------------------
SQL code
select *
from [table] a
where exists (
select 1 from (
select sid, max([Series No]) as maxSNo
from [table]
group by sid
) as b
where b.sid = a.sid and a.[Series No] = maxSNo
)
and not exists (
select 1 from [table] b
where b.sid = a.sid
and b.[Series No] = a.[Series No]
and b.Version > a.Version
)
------解决方案--------------------