SQ Questions
SQ Questions
Q: Find employees with tenure less than the average tenure of all employees.
A:
SELECT employee_id, name, tenure
FROM employees
WHERE tenure < (SELECT AVG(tenure) FROM employees);
18. Find the Month with the Highest Revenue in Each Year
Q: Write a query to find the month with the highest revenue for each year.
A:
SELECT year, month, revenue
FROM (
SELECT year, month, revenue,
RANK() OVER (PARTITION BY year ORDER BY revenue DESC) AS
rank
FROM monthly_revenue
) AS yearly_revenue
WHERE rank = 1;