CodeEraFree roadmap

SQL Practice / Numeric functions

SQL Numeric Functions: practice questions with answers

7 questions with solved queries and real output. Outputs checked on MariaDB 10.11 (MySQL-compatible) on 23 November 2026.

Numeric functions do maths inside a query: MOD (remainder), SQRT, FLOOR and CEIL (round down and up), ABS, POWER, and LEAST and GREATEST (smallest and largest of a list of values). You can call a function without a table, for example SELECT POWER(2, 10);.

MOD(a, b)    SQRT(x)    FLOOR(x)    CEIL(x)
ABS(x)       POWER(x, y)
LEAST(a, b, c)    GREATEST(a, b, c)

These questions use the employees table (30 rows). Create it first with the copy-and-paste setup script. Here is the data, so you can check your answers by eye.

See the employees table

Table: employees

emp_nofirst_namelast_namesalarybirth_dategenderjoining_datedepartment
1001JamesBond453001998-01-19M2020-11-29Marketing
1002RobertLee694101998-09-02M2019-12-26IT
1003MaryWood395181997-11-07F2019-09-12Business Development
1004JohnCole362641999-02-01M2021-04-14HR
1005JenniferGill489411996-06-05F2019-06-28Marketing
1006MichaelWatts238001999-04-16M2022-06-09HR
1007DavidMills394001998-04-26M2021-10-17IT
1008WilliamHill263921999-10-21M2019-09-30Business Development
1009LindaPotter552311998-01-24F2021-08-07Finance
1010RichardMartin256001996-08-07M2021-03-23IT
1011SusanHall541521999-12-27F2020-08-07Finance
1012JosephTurner605561997-05-13M2019-09-02Marketing
1013MaryGill582461999-01-21F2021-04-30Business Development
1014ThomasRyan236761996-10-12M2022-03-02IT
1015CharlesWilliams572262000-01-29M2019-11-05NULL
1016JessicaClarkNULL2000-01-25F2020-01-24IT
1017NancyParker669001996-10-24F2022-01-09Finance
1018BettyBarker352881998-11-13F2019-12-26HR
1019ChristopherGibson593411998-04-23M2019-05-02Marketing
1020DanielElliott440121999-01-21M2023-01-08IT
1021DavidMillsNULL1998-01-24M2019-12-26IT
1022SarahHarrison446921996-03-20F2020-05-03Finance
1023MatthewHill413651998-05-16M2019-05-23IT
1024AnthonyMiller567941996-06-30M2019-02-28Business Development
1025MarkWood651201998-10-29M2020-07-30Business Development
1026ElizabethWalker470301998-08-11F2021-06-18NULL
1027BarbaraAndersonNULL1999-12-27F2021-03-14HR
1028JessicaClark638361998-01-24F2021-05-23IT
1029NancyCole636692000-01-26F2019-12-26Finance
1030JoeBrooks440001999-08-05M2021-03-09Business Development

How to use this page: read a question, write your own query, then open "Show the answer" and compare. Trying first is what makes it stick.

Question 1Get all the details of employees whose emp_no is an even number.

Show the answer and the output
SELECT * FROM employees WHERE MOD(emp_no, 2) = 0;

Output

emp_nofirst_namelast_namesalarybirth_dategenderjoining_datedepartment
1002RobertLee694101998-09-02M2019-12-26IT
1004JohnCole362641999-02-01M2021-04-14HR
1006MichaelWatts238001999-04-16M2022-06-09HR
1008WilliamHill263921999-10-21M2019-09-30Business Development
1010RichardMartin256001996-08-07M2021-03-23IT
1012JosephTurner605561997-05-13M2019-09-02Marketing
1014ThomasRyan236761996-10-12M2022-03-02IT
1016JessicaClarkNULL2000-01-25F2020-01-24IT
1018BettyBarker352881998-11-13F2019-12-26HR
1020DanielElliott440121999-01-21M2023-01-08IT
1022SarahHarrison446921996-03-20F2020-05-03Finance
1024AnthonyMiller567941996-06-30M2019-02-28Business Development

Showing the first 12 of 15 rows.

Question 2Get all the details of employees whose emp_no is a perfect square.

Show the answer and the output
SELECT * FROM employees WHERE SQRT(emp_no) = FLOOR(SQRT(emp_no));

Output

emp_nofirst_namelast_namesalarybirth_dategenderjoining_datedepartment
1024AnthonyMiller567941996-06-30M2019-02-28Business Development

A number is a perfect square when its square root has no decimal part, so it equals its own FLOOR.

Question 3Find the average salary of each department, rounded up to the nearest integer, as 'avg_salary'.

Show the answer and the output
SELECT department, CEIL(AVG(salary)) AS avg_salary
FROM employees
GROUP BY department;

Output

departmentavg_salary
NULL52128
Business Development48345
Finance56929
HR31784
IT43900
Marketing53535

CEIL rounds up. ROUND rounds to the nearest and FLOOR rounds down.

Question 4Find the new salary of employees after subtracting 50,000 from their current salary, as 'new_salary', returning only positive values. Also fetch the first name.

Show the answer and the output
SELECT first_name, salary - 50000 AS new_salary
FROM employees
WHERE salary - 50000 > 0;

Output

first_namenew_salary
Robert19410
Linda5231
Susan4152
Joseph10556
Mary8246
Charles7226
Nancy16900
Christopher9341
Anthony6794
Mark15120
Jessica13836
Nancy13669

Different from the PDF: The PDF used WHERE salary-50000 = ABS(salary-50000), which also keeps zero. A simple > 0 says exactly what the question asks.

Question 5Calculate 55 raised to the power of 3, shown as 'power'.

Show the answer and the output
SELECT POWER(55, 3) AS power;

Output

power
166375.0

Question 6Find the smallest of these numbers as 'least_number': 200, 23, 0, 987.5, 32, -1.

Show the answer and the output
SELECT LEAST(200, 23, 0, 987.5, 32, -1) AS least_number;

Output

least_number
-1.0

Question 7Find the largest of these numbers as 'highest_number': 200, 23, 0, 987.5, 32, -1.

Show the answer and the output
SELECT GREATEST(200, 23, 0, 987.5, 32, -1) AS highest_number;

Output

highest_number
987.5

Want these as PDFs? Download the question PDF or the answer PDF to practise offline.