Hi guys...again caught up in an analytical query, initially which I thought would be quite easy but not at the end.
Sample data for this is:
With TestData as
(
Select 2014 AS Yer, 201401 AS WeekNumber, 1 AS Student, 'A' AS Qualification From Dual
Union All
Select 2014 AS Yer, 201401 AS WeekNumber, 2 AS Student, 'A' AS Qualification From Dual
Union All
Select 2014 AS Yer, 201401 AS WeekNumber, 3 AS Student, 'A' AS Qualification From Dual
Union All
Select 2014 AS Yer, 201402 AS WeekNumber, 1 AS Student, 'A' AS Qualification From Dual
Union All
Select 2014 AS Yer, 201402 AS WeekNumber, 2 AS Student, 'A' AS Qualification From Dual
Union All
Select 2014 AS Yer, 201402 AS WeekNumber, 3 AS Student, 'A' AS Qualification From Dual
Union All
Select 2014 AS Yer, 201402 AS WeekNumber, 4 AS Student, 'A' AS Qualification From Dual
Union All
Select 2014 AS Yer, 201403 AS WeekNumber, 1 AS Student, 'A' AS Qualification From Dual
Union All
Select 2014 AS Yer, 201403 AS WeekNumber, 1 AS Student, 'B' AS Qualification From Dual
Union All
Select 2014 AS Yer, 201403 AS WeekNumber, 2 AS Student, 'A' AS Qualification From Dual
Union All
Select 2014 AS Yer, 201403 AS WeekNumber, 5 AS Student, 'A' AS Qualification From Dual
Union All
Select 2014 AS Yer, 201404 AS WeekNumber, 1 AS Student, 'A' AS Qualification From Dual
Union All
Select 2014 AS Yer, 201404 AS WeekNumber, 1 AS Student, 'B' AS Qualification From Dual
Union All
Select 2014 AS Yer, 201404 AS WeekNumber, 2 AS Student, 'A' AS Qualification From Dual
Union All
Select 2015 AS Yer, 201501 AS WeekNumber, 4 AS Student, 'C' AS Qualification From Dual
Union All
Select 2015 AS Yer, 201501 AS WeekNumber, 6 AS Student, 'A' AS Qualification From Dual
Union All
Select 2015 AS Yer, 201501 AS WeekNumber, 7 AS Student, 'D' AS Qualification From Dual
Union All
Select 2015 AS Yer, 201501 AS WeekNumber, 8 AS Student, 'M' AS Qualification From Dual
)
Select *
From TestData
Order By 1, 2, 3, 4
And the required data is:

| YER | WEEKNUMBER | NewStudents |
| 2014 | 201401 | 3 |
| 2014 | 201402 | 1 |
| 2014 | 201403 | 2 |
| 2014 | 201404 | 0 |
| 2015 | 201501 | 4 |
Actually the results should be based on the enrollment of the new students every week. New Students mean the students who have not been enrolled in the same Qualification previously. You can judge this from sample data. If a student appears again in the next week with the same qualification, he is not counted. Therefore only students with new number or the students with new qualification will be counted.
I've tried to use Count(StudentNumber) Over(Partition By WeekNumber Order By WeekNumber Rows Unbounded Preceding)
and few of it's variations but not giving me correct results.
Can you help me for this?
Message was edited by: MUmarAli