0% found this document useful (0 votes)
35 views10 pages

SQL Evaluation Questions - 02-04-24 2

The document provides 20 SQL problems or exercises related to querying and analyzing data from various tables. The problems cover a range of concepts like aggregation, joins, filtering, sorting, updating records, and more. Solutions are required to each problem.

Uploaded by

sgsharan89
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views10 pages

SQL Evaluation Questions - 02-04-24 2

The document provides 20 SQL problems or exercises related to querying and analyzing data from various tables. The problems cover a range of concepts like aggregation, joins, filtering, sorting, updating records, and more. Solutions are required to each problem.

Uploaded by

sgsharan89
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Evaluation on SQL – Dated: 02-04-24

Consider the following table. Find out the consecutive numbers that
appear atleast 3 times. Return Number

2. Write a solution to find the rank of the scores. The ranking should
be calculated according to the following rules:
 The scores should be ranked from the highest to the lowest.
 If there is a tie between two scores, both should have the same
ranking.
 After a tie, the next ranking number should be the next
consecutive integer value. In other words, there should be no
holes between ranks.
 Return the result table ordered by the score in descending order.

3. Write the employee name who is getting salary more than his manager?
4. Write a solution to find managers with at least five direct reports.

5. Write a solution to display the records with three or more rows


with consecutive id's, and the number of people is greater than or
equal to 100 for each.

6. Write a solution to find the people who have the most friends and the most friends number.

7. Report for every three line segments whether they can form a triangle.

The three segments can form a triangle if the first two sides sum is
greater than the third side
8. A single number is a number that appeared only once in the MyNumbers
table. Find the largest single number. If there is no single number,
report null. The result format is in the following example.

9. Write a solution to swap all 'f' and 'm' values (i.e., change all
'f' values to 'm' and vice versa) with a single update statement and
no intermediate temporary tables. Note that you must write a single
update statement, do not write any select statement for this problem.

10. Write a solution to rearrange the Products table so that each row has (product_id, store, price). If
a product is not available in a store, do not include a row with that product_id and store combination
in the result table.
11. Write a solution to calculate the bonus of each employee. The
bonus of an employee is 100% of their salary if the ID of the employee
is an odd number and the employee's name does not start with the
character 'M'. The bonus of an employee is 0 otherwise.

12. Find the IDs of the employees whose salary is strictly less than
$30000 and whose manager left the company. When a manager leaves the
company, their information is deleted from the Employees table, but
the reports still have their manager_id set to the manager that left.
13. Write a solution to calculate the number of unique subjects each
teacher teaches in the university.

14. Employees can belong to multiple departments. When the employee


joins other departments, they need to decide which department is their
primary department. Note that when an employee belongs to only one
department, their primary column is 'N'.
Write a solution to report all the employees with their primary
department. For employees who belong to one department, report their
only department.
15. Write a solution to calculate the number of bank accounts for each
salary category. The salary categories are:
"Low Salary": All the salaries strictly less than $20000.
"Average Salary": All the salaries in the inclusive range [$20000,
$50000].
"High Salary": All the salaries strictly greater than $50000.
The result table must contain all three categories. If there are no
accounts in a category, return 0.

16. The confirmation rate of a user is the number of 'confirmed'


messages divided by the total number of requested confirmation
messages. The confirmation rate of a user that did not request any
confirmation messages is 0. Round the confirmation rate to two decimal
places.
Write a solution to find the confirmation rate of each user.
17. Write a solution to report the IDs of all the employees with
missing information. The information of an employee is missing if:
The employee's name is missing, or
The employee's salary is missing.
Return the result table ordered by employee_id in ascending order.

18. Write a solution to select the product id, year, quantity, and
price for the first year of every product sold.
18. Write a solution to find for each user, the join date and the
number of orders they made as a buyer in 2019.
19. You are the restaurant owner and you want to analyze a possible
expansion (there will be at least one customer every day).
Compute the moving average of how much the customer paid in a seven
days window (i.e., current day + 6 days before). average_amount should
be rounded to two decimal places.
Return the result table ordered by visited_on in ascending order.

20. Write a solution to:


Find the name of the user who has rated the greatest number of movies.
In case of a tie, return the lexicographically smaller user name.
Find the movie name with the highest average rating in February 2020.
In case of a tie, return the lexicographically smaller movie name.

You might also like