The document outlines SQL commands for managing a Bankaccount table, including creating the table, inserting records, selecting data, updating balances, and querying employee and product information. It also provides scenarios for deleting employee records, pending orders, and discontinued products, as well as updating bonuses for employees in the Sales department. The commands demonstrate basic SQL operations such as INSERT, SELECT, UPDATE, and DELETE.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
4 views3 pages
Lab 3
The document outlines SQL commands for managing a Bankaccount table, including creating the table, inserting records, selecting data, updating balances, and querying employee and product information. It also provides scenarios for deleting employee records, pending orders, and discontinued products, as well as updating bonuses for employees in the Sales department. The commands demonstrate basic SQL operations such as INSERT, SELECT, UPDATE, and DELETE.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3
CREATE TABLE Bankaccount(
account_id SERIAL PRIMARY KEY,
acc_holder_name VARCHAR(50) NOT NULL, acc_balance DECIMAL(38,2) ); --TASK_1-- INSERT INTO Bankaccount VALUES (20240101,'Raj Sharma',250.01), (20240115,'Roger White',68000.6), (20240322,'Kavita Rao',450004), (20240601,'Arjun Verma',5500.03), (20140730,'Priya Singh',6000.04); --TASK_2-- SELECT acc_holder_name,acc_balance FROM Bankaccount; --TASK_3-- SELECT acc_holder_name,acc_balance FROM Bankaccount WHERE acc_balance > 30000.00; --TASK_4-- UPDATE Bankaccount SET acc_balance = 23000.00 WHERE account_id = 20240101; --LAB_1-- SELECT * FROM STUDENT ORDER BY LASTNAME; --LAB_2-- SELECT Gender,COUNT(Gender) FROM STUDENT WHERE STUDENT_ID BETWEEN 1001 AND 1008 GROUP BY Gender; --DAY_2-- --LAB_1-- ALTER TABLE Employee ADD Salary DECIMAL(20,0) DEFAULT 20000.00, ADD Department VARCHAR(10); SELECT * FROM Employee WHERE Salary > 50000 AND Department = 'IT'; --LAB_2-- SELECT * FROM Product WHERE Category = 'Electronics' OR Price < 70000; --LAB_3-- SELECT department, AVG(salary) AS avg_salary FROM employee GROUP BY department; ChatGPT Exercise --Scenario 1-- To retrieve information about employees who belong to the "Sales" department and have a salary greater than 50,000, you can use the following SQL SELECT query: SELECT * FROM employees WHERE department = 'Sales' AND salary > 50000; Explanation: • SELECT *: Retrieves all columns from the employees table. • FROM employees: Specifies the table to query from (in this case, the employees table). • WHERE department = 'Sales': Filters the results to include only employees from the "Sales" department. • AND salary > 50000: Further filters the results to include only employees with a salary greater than 50,000. --Scenario 2-- To remove an employee's record from the "employees" table after they have resigned, you can use the following SQL DELETE query. You would typically identify the employee by their unique identifier, such as employee_id, assuming you have that in the table. Here’s an example SQL query that deletes the record of an employee with a specific employee_id: DELETE FROM employees WHERE employee_id = <employee_id>; Explanation: • DELETE FROM employees: Specifies the table (employees) from which to delete the record. • WHERE employee_id = <employee_id>: Specifies the condition for the deletion, identifying the employee by their unique employee_id. Replace <employee_id> with the actual employee ID of the person who resigned. Note: Ensure you have a backup or confirmation step in place before running a DELETE operation, as it permanently removes the data. --Scenario 3-- To delete all orders placed before '2022-01-01' that are still in the 'Pending' status, you can use the following SQL DELETE query: DELETE FROM orders WHERE order_date < '2022-01-01' AND status = 'Pending'; Explanation: • DELETE FROM orders: Specifies the table (orders) from which to delete records. • WHERE order_date < '2022-01-01': Filters the orders placed before January 1, 2022. • AND status = 'Pending': Further filters the orders to include only those that are still in the 'Pending' status. This query will remove all orders that meet both conditions: placed before the specified date and with a status of 'Pending'. --Scenario 4-- To remove all products from the "Discontinued" category, you can use the following SQL DELETE query: DELETE FROM products WHERE category = 'Discontinued'; Explanation: • DELETE FROM products: Specifies the table (products) from which to delete records. • WHERE category = 'Discontinued': Filters the products to only those in the "Discontinued" category. This will delete all products that belong to the "Discontinued" category. Make sure to double-check before executing this query to ensure that you only remove the intended records. --Scenario 5-- To add 1000 to the bonus column for all employees in the "Sales" department, you can use the following SQL UPDATE query: UPDATE employees SET bonus = bonus + 1000 WHERE department = 'Sales'; Explanation: • UPDATE employees: Specifies the table (employees) to update. • SET bonus = bonus + 1000: Increases the value of the bonus column by 1000 for each employee in the "Sales" department. • WHERE department = 'Sales': Limits the update to employees who are in the "Sales" department.