Fix Error “The function ‘NTILE’ must have an OVER clause” in SQL Server

If you’re getting SQL Server error 10753 that reads “The function ‘NTILE’ must have an OVER clause”, it’s probably because you’re calling the NTILE() function without an OVER clause.

The NTILE() function requires an OVER clause (and that clause must have an ORDER BY clause).

To fix this issue, be sure to include an OVER clause when calling the NTILE() function.

Example of Error

Here’s an example of code that produces the error:

SELECT
    VendorId,
    ProductName,
    ProductPrice,
    NTILE( 3 )
FROM Products;

Result:

Msg 10753, Level 15, State 3, Line 5
The function 'NTILE' must have an OVER clause.

Here I called the NTILE() function without an OVER clause, which resulted in an error.

Solution

To fix this issue, simply add an OVER clause to the NTILE() function:

SELECT
    VendorId,
    ProductName,
    ProductPrice,
    NTILE( 3 ) OVER ( 
        ORDER BY ProductPrice 
        ) AS NTILE
FROM Products;

Result:

VendorId  ProductName                      ProductPrice  NTILE
--------  -------------------------------  ------------  -----
1004      Bottomless Coffee Mugs (4 Pack)  9.99          1    
1003      Hammock                          10            1    
1001      Long Weight (green)              11.99         1    
1004      Tea Pot                          12.45         1    
1001      Long Weight (blue)               14.75         2    
1001      Left handed screwdriver          25.99         2    
1001      Right handed screwdriver         25.99         2    
1002      Sledge Hammer                    33.49         3    
1003      Straw Dog Box                    55.99         3    
1003      Chainsaw                         245           3    

This time we got the expected result.

It’s important to remember that the OVER clause must have an ORDER BY clause. Omitting this will cause a different error.