Find Employees with High Salaries
Given an Employee table with columns id, name, and salary, which SQL clause should be used to select employees earning more than 5000?
- A. WHERE salary u003E 5000
- B. HAVING salary u003E 5000
- C. SELECT salary u003E 5000
- D. ORDER BY salary u003E 5000
- E. GROUP BY salary u003E 5000
Customers Without Orders
Suppose you have Customers and Orders tables linked by customer_id. Which SQL operation will return all customers who never placed an order?
- A. LEFT JOIN with Orders and filter where Orders.customer_id IS NULL
- B. INNER JOIN on Orders by customer_id
- C. UNION of Customers and Orders
- D. SELECT Customers where id NOT IN Orders
- E. CROSS JOIN Customers and Orders
Second Highest Salary
Which SQL query finds the second-highest salary from the Employee table?
- A. SELECT MAX(salary) FROM Employee WHERE salary u003C (SELECT MAX(salary) FROM Employee)
- B. SELECT TOP 2 salary FROM Employee
- C. SELECT MIN(salary) FROM Employee
- D. SELECT salary FROM Employee LIMIT 2
- E. SELECT MAX(salary) FROM Employee
Department with the Highest Average Salary
Given Employee and Department tables, how do you find the department with the highest average salary?
- A. GROUP BY department and ORDER BY average salary DESC LIMIT 1
- B. GROUP BY department and ORDER BY MAX(salary)
- C. SELECT department WHERE AVG(salary)
- D. HAVING MAX(salary) FROM Department
- E. GROUP BY salary in Department
Identifying Duplicate Emails
In a Person table with an email column, which SQL is best to find all duplicate emails?
- A. SELECT email FROM Person GROUP BY email HAVING COUNT(email) u003E 1
- B. SELECT email FROM Person WHERE COUNT(*) u003E 1
- C. SELECT DISTINCT email FROM Person
- D. ORDER BY email FROM Person
- E. GROUP BY email FROM Person
Ranking Employee Salaries
If you want to assign a rank to each employee based on salary, giving equal salaries the same rank, which SQL window function would you use?
- A. RANK() OVER (ORDER BY salary DESC)
- B. ROWCOUNT() OVER (ORDER BY salary)
- C. COUNT() GROUP BY salary
- D. INDEX() FROM Employee
- E. COLLECT() OVER salary
Employees Earning More Than Their Managers
Which SQL clause helps you compare an employee's salary to their manager's salary when both are in the same Employee table?
- A. JOIN Employee as e ON manager_id = e.id
- B. SELECT DISTINCT salary FROM Employee
- C. GROUP BY manager_id
- D. WHERE salary u003E 1.1*manager_salary
- E. HAVING salary u003E MAX(salary)
Finding the Median Salary
What SQL window function can be used to help find the median salary from an Employee table?
- A. ROW_NUMBER() OVER (ORDER BY salary)
- B. SUM() OVER (partition BY salary)
- C. COUNT() OVER (ORDER BY salary)
- D. MIN() GROUP BY salary
- E. AVG(salary, median)
GROUP BY Usage
Which scenario best demonstrates when to use GROUP BY in SQL?
- A. When calculating the total salary per department
- B. When retrieving all columns without aggregation
- C. When filtering rows based on a value
- D. When updating salaries in bulk
- E. When deleting duplicate rows
HAVING vs WHERE
In SQL, when should you use HAVING instead of WHERE in a query?
- A. To filter results after aggregation, like selecting departments with average salary over 5000
- B. To filter individual rows before grouping
- C. To sort the query results by a column
- D. To join two unrelated tables
- E. To update a specific column's value