Queries Practice
Queries Practice
Basic to Advanced
Introduction
This document presents a set of 15 SQL (MySQL) queries designed for freshers prepar-
ing for interviews at companies like LTI Mindtree, Infosys, and similar IT firms. The
queries are categorized into basic, intermediate, and advanced levels to demonstrate a
clear progression in complexity. Each question includes a brief description of the task,
and answers are provided at the end.
1
8. Write a query to calculate the average salary for each department in the Employees
table, including only departments with more than 3 employees.
9. Write a query to find employees in the Employees table whose salary is higher than
the average salary across all employees.
10. Write a query to identify duplicate employee records in the Employees table based
on first_name.
Answers
Basic Level Answers
1. Retrieve employees with salary ≥ 40000:
SELECT emp_id , first_name , salary
FROM Employees
WHERE salary >= 40000;
5. Count employees:
2
SELECT COUNT (*) AS employee_count
FROM Employees ;
3
SELECT customer_id , SUM ( amount ) AS total_amount
FROM Orders
WHERE order_date >= DATE_SUB ( CURDATE () , INTERVAL 1 YEAR )
GROUP BY customer_id
HAVING total_amount > 1000;
Preparation Tips
• Practice queries on platforms like LeetCode or HackerRank.
• Understand MySQL-specific functions (e.g., DATE_SUB, window functions).
• Review database concepts like normalization and indexing.
4
• Simulate interview scenarios to build confidence.