0% found this document useful (0 votes)
13 views17 pages

Practice Clauses Tough Level

Uploaded by

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

Practice Clauses Tough Level

Uploaded by

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

• Employees Whose Salary is Greater Than Their Manager’s Salary

• Select emp_id,emp_name,salary, from employee emp join employee


mngr on emp.emp_id=mngr.managr_id where
emp.salary>mngr.salary;
• SELECT e.employee_id, e.name, e.salary, m.name AS manager_name,
m.salary AS manager_salary
• FROM employees e
• JOIN manager m ON e.emp id = m.id
• WHERE e.salary > m.salary;
• Orders Placed in the Last 3 Months but Not by Premium Customers
• SELECT order_id, customer_id, order_date
• FROM orders
• WHERE order_date >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH)
• AND customer_id NOT IN (
• SELECT customer_id
• FROM customers
• WHERE customer_type = 'Premium'
• );
• Products Whose Price is Above Average Price of All Products
• SELECT product_id, product_name, price
• FROM products
• WHERE price > (SELECT AVG(price) FROM products);
• Students Who Have Enrolled in Both ‘Math’ and ‘Science’
SELECT student_id
FROM enrollments
WHERE course_name IN ('Math', 'Science')
GROUP BY student_id
HAVING COUNT(DISTINCT course_name) = 2;
• Employees with Highest Salary in Each Department but Salary > 50000
• SELECT department_id, MAX(salary) AS max_salary
• FROM employees
• WHERE salary > 50000
• GROUP BY department_id
• ORDER BY max_salary DESC;
• Departments Having More Than 5 Employees with Average Salary <
40000

• Select dept from employees group by dept having count (emp)>5 and
avg(salary)<40000;
• SELECT department_id, COUNT(*) AS emp_count, AVG(salary) AS
avg_salary
• FROM employees
• WHERE salary < 40000
• GROUP BY department_id
• HAVING COUNT(*) > 5
• ORDER BY avg_salary ASC;
• Customers with Total Purchase Amount > 1 Lakh, Displaying in
Descending Order
• SELECT customer_id, SUM(purchase_amount) AS total_spent
• FROM orders'
• GROUP BY customer_id
• HAVING SUM(purchase_amount) > 100000
• ORDER BY total_spent DESC;
• Products Sold More Than 100 Times with Average Selling Price > 500
• SELECT product_id, COUNT(*) AS total_sold, AVG(selling_price) AS
avg_price
• FROM sales
• WHERE selling_price > 500
• GROUP BY product_id
• HAVING COUNT(*) > 100
• ORDER BY total_sold DESC, avg_price DESC;

You might also like