Hi Sagar
Pls try the following query for your additional requirement
Sel
Send_Date
,sum(file_count)
,max(Non_Seq_Flag)
from
(sel
Serial_Number
,Send_Date
,max(cnt) file_count
,case when max(diff) > 1 then 'Yes' else 'No' end as Non_Seq_Flag
,max(file_number) as Min_Seq
,min(file_number) as Max_Seq
from
(
sel
Serial_Number
,Send_Date
,File_Number
,count(*) over (partition by Serial_Number,Send_Date order by file_number)as cnt
,coalesce(mdiff(file_number,1,file_number),0) as diff
from
tab
group by 1,2
)a
group by 1,2
)b
group by 1
order by 1;
let me know if this works
Also you can learn about the analytical functions here -
http://www.coffingdw.com/sql/tdsql.htm
refer to chapter 10
Regards
Rajeev
↧