October 22, 2024
Chicago 12, Melborne City, USA
SQL

Detect and ignore anomalous number in MySQL MIN/MAX query


I am trying to find the MIN and MAX of a simple data set….

Score
15
12
8
28
5

Simply doing this would work.

SELECT MIN(Score) AS minScore, MAX(Score) AS maxScore FROM Scores;

Which should return 5 and 28.
But what if somehow a huge number ended up in the set throwing off the results…

Score
15
120000
8
28
5

This would return 5 and 120000.

What I need to do is to somehow have the query detect the unusually large number and ignore it in the result returning 5 and 28.

The actual set would have a large numbers in a certain unknown range, so the anomaly should stand out. Was hoping for some sort of mathematical way to omit the anomaly.

Not exactly the same as the similar question given….
This seems to omit some of the top numbers outside of the anomaly, which probably wouldn’t change the average much, but in my case I need the actual MIN and MAX values omitting the anomaly. Also, I cant use a subquery, must be a straight calculation to determine the number.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video