Assignment2 Unit2
Assignment2 Unit2
Q1. Write an SQL query to retrieve the following details from a "Sales" table: (5 Marks)
• Total sales amount for each month in the year 2024.
• Display the result with the following columns: Month, Total Sales.
• Ensure the results are sorted in ascending order by month.
Sample Table Schema:
Sales (SaleID, SaleDate, Amount)
Q2. Consider the following tables: (5 Marks)
• Employees (EmpID, Name, Salary, DepartmentID)
• Departments (DepartmentID, DepartmentName)
Write an SQL query to find the names of employees who earn more than the average salary of
their respective department.
Q3. Given the tables below: (5 Marks)
• Students (StudentID, Name, CourseID)
• Courses (CourseID, CourseName)
• Enrollments (EnrollmentID, StudentID, CourseID)
Write an SQL query that retrieves the names of students who are enrolled in at least one course
but excludes those enrolled in the course titled "Data Science".
Q4. Create a view named HighValueCustomers that displays customer details from the Orders
table where the total order value exceeds ₹50,000. (5 Marks)
Orders (OrderID, CustomerID, OrderDate, OrderAmount)
Your query should:
• Display CustomerID, TotalOrders, and TotalAmount.
• Use the GROUP BY clause.
Q5. Transaction Control Commands (5 Marks)
Consider the table BankAccounts (AccountID, AccountHolder, Balance).
Write an SQL transaction that:
• Begins with a transaction block.
• Deducts ₹5,000 from AccountID 1001 and adds ₹5,000 to AccountID 1002.
• Includes appropriate COMMIT, ROLLBACK, and SAVEPOINT commands to manage
transaction control effectively.