wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz on Window Functions

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

Which keyword is always required when using a window function?

a)

GROUP BY

b)

HAVING

c)

OVER()

d)

DISTINCT

2.

What does the ROW_NUMBER() function return?

a)

A unique sequential number per row in the partition

b)

The cumulative count of rows

c)

The highest row number in a partition

d)

The same rank for equal values

3.

Which of these functions assigns the same rank to equal values but leaves gaps in ranking?

a)

DENSE_RANK()

b)

RANK()

c)

ROW_NUMBER()

d)

NTILE()

4.

Which function assigns continuous ranking without gaps even if values are the same?

a)

ROW_NUMBER()

b)

DENSE_RANK()

c)

RANK()

d)

NTILE()

5.

What does the following query do? SELECT emp_id, salary, SUM(salary) OVER(PARTITION BY dept_id) AS dept_total FROM employees;

a)

Returns cumulative salary in each department row-wise

b)

Returns total salary for each department repeated for all employees in that department

c)

Returns only one row per department

d)

Returns total salary for the whole table

6.

Which window function is used to get the previous row’s value?

a)

LEAD()

b)

RANK()

c)

LAG()

d)

NTILE()

7.

Which window function is used to get the next row’s value?

a)

LEAD()

b)

LAG()

c)

FIRST_VALUE()

d)

LAST_VALUE()

8.

Which of the following is NOT a window function in MySQL?

a)

NTILE()

b)

FIRST_VALUE()

c)

SUM()

d)

GROUP_CONCAT()

9.

What does the NTILE(4) function do?

a)

Divides rows into 4 groups as equally as possible

b)

Returns the top 4 ranked rows

c)

Splits the table into 4 partitions

d)

Returns 4 values from each group

10.

If you use a window function with OVER() but without PARTITION BY, what happens?

a)

Function is applied to the entire result set

b)

Function returns NULL

c)

Query gives an error

d)

Only the first row is processed

11.

Which window function gives the first value in the ordered set within a partition?

a)

LEAD()

b)

LAG()

c)

FIRST_VALUE()

d)

LAST_VALUE()

12.

Which window function gives the last value in the ordered set within a partition?

a)

NTILE()

b)

LAST_VALUE()

c)

LAG()

d)

RANK()

13.

What does the following query output? SELECT salary, SUM(salary) OVER(ORDER BY salary) AS running_total FROM employees;

a)

Total salary of all employees

b)

Running cumulative total ordered by salary

c)

Maximum salary only

d)

Average salary

14.

Which of the following can be used with window functions but not with aggregate functions?

a)

PARTITION BY

b)

OVER()

c)

ORDER BY inside OVER()

d)

ALL of the above

15.

Which function would you use to get a moving average?

a)

RANK()

b)

ROW_NUMBER()

c)

AVG() OVER(ORDER BY … ROWS BETWEEN …)

d)

NTILE()

16.

If two employees have the same salary, how does ROW_NUMBER() handle them?

a)

Assigns the same row number

b)

Assigns different row numbers arbitrarily

c)

Returns NULL

d)

Throws an error

17.

Which of these is true about aggregate vs window functions?

a)

Aggregate functions return one row per group, window functions return values for every row

b)

Window functions replace GROUP BY

c)

Aggregate functions cannot use OVER()

d)

Both A and C

18.

What will happen if you use ORDER BY inside OVER() with no PARTITION BY?

a)

Results are ordered globally and function is applied over entire result set

b)

MySQL throws an error

c)

Results are returned randomly

d)

Each row is grouped by itself

19.

Which window function divides rows into quartiles, deciles, etc.?

a)

NTILE()

b)

RANK()

c)

DENSE_RANK()

d)

ROW_NUMBER()

20.

What does CUME_DIST() return?

a)

Cumulative distribution of a value relative to the entire set

b)

Row number in the partition

c)

Average rank of the value

d)

The count of rows till current

21.

Which window function returns the relative standing of a row between 0 and 1?

a)

RANK()

b)

PERCENT_RANK()

c)

NTILE()

d)

DENSE_RANK()

22.

Which window function can be used to calculate a sliding window total?

a)

ROW_NUMBER()

b)

SUM() OVER(ORDER BY … ROWS BETWEEN …)

c)

RANK()

d)

NTILE()

23.

What happens if you use an aggregate function like SUM() without OVER()?

a)

It works as a normal aggregate function

b)

It becomes a window function

c)

MySQL throws an error

d)

Returns NULL

24.

Which of these statements about window functions is correct?

a)

They collapse rows like GROUP BY

b)

They return values for every row without collapsing

c)

They always need PARTITION BY

d)

They cannot use ORDER BY

25.

Window functions are evaluated at which stage in query execution?

a)

Before WHERE

b)

Before GROUP BY

c)

After SELECT and aggregation

d)

Before FROM