我在计算sql语句中row_number
的最大值时遇到了麻烦。
我查询搜索OriginalDocumentNumber
,但数据与查询全部不一样
http://i.stack.imgur.com/xwVN9.png
select
OriginalDocumentNumber, FilterRound, p2_Reason, rowno, p2_FinalGrade
from
(select * ,row_number() over (partition by OriginalDocumentNumber,FilterRound order by p2_FinalGrade desc) rowno
from #TempDa
) l
where
l.p2_FinalGrade in ('d','f')
and l.rowno = 1
and l.OriginalDocumentNumber='590200054'
and l.OriginalDocumentNumber+l.FilterRound not in (select OriginalDocumentNumber+FilterRound from #TempDa where p2_FinalGrade in ('a','b','c'))
查询2输出image query 2
select OriginalDocumentNumber ,FilterRound , p2_Reason , rowno , p2_FinalGrade from ( select * ,row_number() over (partition by OriginalDocumentNumber,FilterRound order by p2_FinalGrade desc) rowno from #TempDa ) l where l.p2_FinalGrade in ('d','f') and l.rowno = 1 -- and l.OriginalDocumentNumber='590200054' and l.OriginalDocumentNumber+l.FilterRound not in (select OriginalDocumentNumber+FilterRound from #TempDa where p2_FinalGrade in ('a','b','c'))