SQL Evaluation Questions - 02-04-24 2
SQL Evaluation Questions - 02-04-24 2
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.
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.
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.