I\'m trying to calculate the mode of a series of idsofInterest in a table, each with an accompanying valueOfInterest such:
idsOfInterest | valueOfInterest
The mode is the most common value. You can get this with aggregation and row_number()
:
select idsOfInterest, valueOfInterest
from (select idsOfInterest, valueOfInterest, count(*) as cnt,
row_number() over (partition by idsOfInterest order by count(*) desc) as seqnum
from table t
group by idsOfInterest, valueOfInterest
) t
where seqnum = 1;