I have two rank functions and one works as expected. However, the other one ranks one partition before the other partitions. Here's the code:
if(count1>=3 and count2>=2 and count3>=2,
rank() over (partition by examdateID, sClass Order By orderColumn desc), count(StudentID) over (partition by examdateID, sClass)) as ClassRank ,
if(count1>=3 and count2>=2 and count3>=2,
rank() over (partition by examDateID, sClass, stream Order By orderColumn desc), count(StudentID) over (partition by examdateID, sClass, stream )) as StreamRank from...
I have two streams and I expect the classRank will give a rank of all students across the streams. However all in stream 1 are ranked before stream 2 ...3.. etc
if the condition (count1,2,3) is not met, I just expect the total number of students
could you point me in the right direction?
I'm using MariaDb 10.4.10
Edit:: I've realized that the problem is the if... when I remove it, ranking is ok Maybe rank() can't be put inside if... still need suggestions