Dbms Lab
Dbms Lab
Table: Categories
Table: Employees
Table: OrderDetails
Table: Orders
Table: Products
Table: Shippers
Table: Suppliers
SQL CODE TO MAKE THIS DATABASE IS AS BELOW:
TO CREATE A DATABASE:
CREATE DATABASE hamropasal;
Q.6 Display all records if every price is given a 20% raise in products table.
SELECT ProductID,ProductName,SupplierID,CategoryID,Unit,Price*1.2
FROM products;
Q.7 Display all records of products whose price is greater than 20.
SELECT * FROM products
WHERE Price>20;
LAB 3 : TO CREATE A DATABASE test WITH MULTIPLE TABLES AND
ATTRIBUTES AND USE OF CRUD OPERATION :
Q.2 Display the details of the employee that works for Nepal Bank and has salary
>10000.
SELECT E.person_name,E.street,E.city
FROM Employee E, Works W
WHERE E.person_name=W.person_name AND W.bank_name='Nepal Bank' AND
W.salary>10000;
Answer:
i. CREATE TABLE Actress_Details
(
Players_id int not null,
Actress_namevarchar(50),
Debut_year int,
Recent_releasevarchar(50),
Actress_fee int,
PRIMARY KEY (Players_id)
);
INSERT INTO actress_detailsVALUES(1, 'Renu', 2010, 'Samay', 400000);
INSERT INTO actress_detailsVALUES(2, 'Sita', 2022, 'Radha', 300000);
INSERT INTO actress_detailsVALUES(3, 'Geeta', 2001, 'Mato', 600000);
INSERT INTO actress_detailsVALUES(4, 'Amita', 1990, 'Man', 700000);
INSERT INTO actress_detailsVALUES(5, 'Karishma', 1989, 'Prem', 100000);
i. Display ID of Patient admitted to hospital at Pokhara and whose name ends with
's'.
SELECT PatientID
FROM Hospitals H
INNER JOIN Patients P ON H.PatientID = P.PatientID
WHERE HospitalName = 'Pokhara' AND PatientName LIKE '%s';
ii. Delete the record of Doctors whose salary is greater than the average salary of
doctors.
- DELETE FROM Doctors
WHERE Salary > (SELECT AVG(Salary) FROM Doctors);
iii. Increase the salary of doctors by 18.5% who works in OPD department.
-UPDATE Doctors
SET Salary = Salary * 1.185
WHERE Department = 'OPD';
iv. Find the average salary of Doctors for each address who have average salary
more than 55K.
SELECT Address, AVG(Salary) AS AvgSalary
FROM Doctors
GROUP BY Address
HAVING AVG(Salary) > 55000;