Fix Error “argument of ntile must be greater than zero” in PostgreSQL

If you’re getting an error that reads “ERROR: argument of ntile must be greater than zero” in PostgreSQL, it’s probably because you’re calling the ntile() function with a non-positive integer.

This error occurs when we pass a non-positive integer to the ntile() function.

To fix this issue, be sure to pass a positive integer to the function.

Continue reading

5 Ways to Get a Value from a Different Row in the Same Column in MySQL

MySQL includes some nonaggregate window functions that allow us to get a value from a specific row. We can use such functions to do things like, compare the value in the specified row with the value in the current row, even if both values are in the same column.

Below are five functions that we can use to do this.

Continue reading

RANK() vs DENSE_RANK() in SQL: What’s the Difference?

Many RDBMSs include both a rank() and a dense_rank() function in their list of window function offerings. At first glance, these functions might appear to do the same thing. However, there’s one important difference between these functions, and you will definitely need to be aware of this difference when choosing which function to use.

Continue reading