Assignment SQL
Assignment SQL
2. Write an SQL query to update the age of student with id 1001 to 19 in the students table.
3.Write an SQL query to delete the student with id 1001 from the students table.
4. Suppose you have two tables called customers and orders. The customers table has columns customer
id, first_ name, and last_ name. The orders table has columns order_ id, customer _id, and order_
total. Write an SQL query to join these two tables on the customer _id column and return a list of all
customers with their total order amounts.
FROM customers c
5. Suppose you have two tables called employees and salaries. The employees table has columns emp_
no, first_ name, last _name, and dep t_no. The salaries table has columns emp _no and salary. Write
an SQL query to calculate the average salary of all employees in each department.
FROM employees e
6. Write an SQL query to find the total number of orders placed by each customer in the orders table.
FROM orders
GROUP BY customer_id;
7. Write an SQL query to find the highest salary of employees in each department in
the employees and salaries tables.
ANS: SELECT p. product_ id, p. product _name, SUM(p. price) AS total _revenue
FROM products p
9. Write an SQL query to find the average age of male and female students in the students table using
UNION.
FROM students
UNION
FROM students
10. Suppose you have a table called sales with columns sale_id, date, and amount. Write an SQL query
to find the total amount of sales for each month and year combination.
FROM SALES