wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Windows Functions

Total questions: 13

Worksheet time: 39mins

Name
Class
Date
1.

Full name

4 lines
2.

Email ID

4 lines
3.

Student ID

4 lines
4.

Which all statements are NOT true about Windows Function?

a)

They summarizes the values in the table

b)

They perform calculation on set of rows somehow related to current row

c)

They create different groups and performs aggregation

d)

They are used to find out the Rank

5.

With regards to Rank and Dense Rank, which statements are true?

a)

RANK skips the number of positions after records with the same rank number.

b)

RANK DENSE returns position numbers and it doesn’t skip records with the same rank number

c)

RANK & DENSE RANK are same when there is no tie

d)

All of above

6.

To narrow a window function's application to a subgroup within a data set, use __________.

a)

PARTITION

b)

OVER

c)

SUBGROUP

d)

GROUP

7.

Write a query to find the subject wise Rank.

a)

SELECT subjects, s_name, mark,

rank() OVER ( partition by subjects order by mark desc ) AS 'Rnk' FROM result;

b)

SELECT subjects, s_name, mark , rank() OVER (order by mark asc ) AS 'Rnk' FROM result;

c)

SELECT subjects, s_name, mark, rank() OVER ( partition by subjects) AS 'Rnk' FROM result;

d)

SELECT subjects, s_name, mark, rank() OVER ( partition by s_name order by mark ) AS 'Rnk' FROM result;

8.

Which Query will give the desired result?

a)

SELECT Country, Prod_name, Sales, SUM(Sales)

OVER(PARTITION BY Country) as grand_total   

FROM table;

b)

SELECT Country, Prod_name, Sales, SUM() OVER(PARTITION BY prod_name) as grand_total FROM table;

c)

SELECT Country, Prod_name, Sales, grand_total OVER(PARTITION BY Prod_name) FROM Product_Sales;

d)

SELECT Country, Prod_name, Sales, SUM(Sales) OVER(PARTITION BY Emp_Name) as grand_total FROM Product_Sales;

9.

Which SQL query retrieves the details of the top 3 rank holders from the student table, considering that the ranks are determined based on the mtest column?

a)

"select id, name, mtest,

rank() over (order by mtest desc) as Rnk

from student

where mtest is not null

having Rnk <= 3;"

b)

"with c as (

select id, name, mtest,

rank() over (order by mtest desc) as Rnk

from student

where mtest is not null)

select *

from C

where Rnk <= 3;"

c)

"with c as (

select id, name, mtest,

rank() over (order by mtest desc) as Rnk

from student

where mtest is not null)

select *

from C

having Rnk <= 3;"

d)

"select id, name, mtest,

rank() over (order by mtest desc) as Rnk

from student

where mtest is not null

and Rnk <= 3;"

10.

"7. What will be the output of the following query?

select name, mtest, class, ntile(4) over (order by name) as team

from student

where class is not null;"

a)

It'll create a new column named 'team' and assign a number between 1-4 for each student, sorted by their names.

b)

It'll create a new column named 'team' and assign values that represent the quartiles of the mtest, sorted by their names.

c)

It'll create a new column named 'team' and assign a number between 1-4 for each student, sorted by their names descending order.

d)

It'll create a new column named 'team' and assign values based on the mtest, sorted by their names ascending order.

11.

8. Compare highest marks of mtest in each class with individual marks and show individual mtest in descending order?

a)

"select Name, Class, Mtest,

high(mtest) over (partition by class order by mtest desc) as MxMtest

from student;"

b)

"select Name, Class, Mtest,

max(mtest) over (partition by class order by mtest ) as MxMtest

from student;"

c)

"select Name, Class, Mtest,

max(mtest) over (partition by class order by mtest desc) as MxMtest

from student;"

d)

"select Name, Class, Mtest,

max(mtest) over (order by mtest desc) as MxMtest

from student;"

12.

What is the primary purpose of using the LEAD() function in SQL?

a)

It assigns a consecutive rank to each row within a partition of a result set.

b)

It is useful in case, the current row values need to be compared with the data/value of the previous record.

c)

It distributes rows of an ordered partition into a pre-defined number of roughly equal groups

d)

It allows to access data of the following row, or the row after the subsequent row, and continue on.

13.

What is the primary role of the DENSE_RANK() function in SQL?

a)

It assigns a consecutive rank to each row within a partition of a result set.

b)

It is useful in case, the current row values need to be compared with the data/value of the previous record.

c)

It distributes rows of an ordered partition into a pre-defined number of roughly equal groups

d)

It allows to access data of the following row, or the row after the subsequent row, and continue on.