Dbms Activity
Dbms Activity
DBMS ACTIVITY
Find employees whose salary is higher than the average salary of all employees:
SELECT name
FROM Employees
WHERE salary > (SELECT AVG(salary) FROM Employees);
List all departments where the number of employees is greater than the number of employees in
the "Sales" department:
SELECT department_name
FROM Departments
WHERE (SELECT COUNT(*) FROM Employees WHERE Employees.department_id =
Departments.department_id)
> (SELECT COUNT(*) FROM Employees WHERE department_id = (SELECT department_id FROM
Departments WHERE department_name = 'Sales'));
Display order details along with customer names by joining "Orders" and "Customers":
Retrieve all employees, including those without assigned departments (LEFT JOIN):
Find employees in "HR" or "IT" departments, excluding those with salary > 80,000:
SELECT employee_name
FROM Employees
WHERE department_id IN (SELECT department_id FROM Departments WHERE department_name
IN ('HR', 'IT'))
AND salary <= 80000;
Display total sales for each product where total sales exceed 5000:
SELECT Products.product_name
FROM Orders
JOIN Customers ON Orders.customer_id = Customers.customer_id
JOIN OrderDetails ON Orders.order_id = OrderDetails.order_id
JOIN Products ON OrderDetails.product_id = Products.product_id
WHERE Customers.city = 'New York';