I'm trying to write a SQL query to find the mode, i.e. the element that occurs more often than other elements. For example:
2,2,1,1---->在这里,输出应该为空(1和2都出现了两次) 3,3,3----->在这里,输出也应该为空(没有第二个元素) 3,3,1----->在这里,输出应该是3。(3的出现次数大于1的出现次数)
Here are the 3 conditions used to find it. How can I implement it?
You can count the number of values to find the most frequent value, and you can also filter based on the number of values:
Actually, you can achieve this using the
having
clause andorder by
: