From the course: PostgreSQL: Advanced Queries

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Find the most frequent value within a dataset with MODE

Find the most frequent value within a dataset with MODE - PostgreSQL Tutorial

From the course: PostgreSQL: Advanced Queries

Find the most frequent value within a dataset with MODE

- [Instructor] The mode of a dataset is the value that occurs the most often, and it's another way to understand the central tendency of the data. PostgreSQL includes a mode function that finds this value, but its usage comes with a very large warning that you need to be aware of. Let's first find the mode of our height data, and then take a look at the problem with the calculation. The mode function itself doesn't take any arguments, but, like percentile, the mode function is another ordered-set aggregate function, so it uses the within group order by syntax. I want to find the mode of our height inches column and we'll pull that column from the public dot people heights table. Now, if we don't include a group by clause in this query, it'll simply find the most frequently occurring value within the entire table column. If I execute the query, the result tells me that 66.17 inches is the most common height. Now that may be…

Contents