Database Practical
Database Practical
Database Practical
SELECT Stud_name
FROM Student
WHERE gender = 'M';
SELECT Student.*
FROM Student, lss_rec_
WHERE Student.Stud_no = lss_rec_.Stud_no
GROUP BY Student.Stud_no
HAVING COUNT(lss_rec_.iss_no) > 2;
SELECT Book_.*
FROM Book_, lss_rec_
WHERE Book_.book_no = lss_rec_.book_no
AND MONTH(lss_rec_.iss_date) = 7
AND YEAR(lss_rec_.iss_date) = 2023;
SELECT Book_.*
FROM Book_, lss_rec_, Student
WHERE Book_.book_no = lss_rec_.book_no
AND lss_rec_.Stud_no = Student.Stud_no
AND Student.Stud_name = 'Krishna';
SELECT *
FROM Employee
WHERE l_name LIKE '%kumar%';
List the ID and names of employees who joined after June 1, 2018
List the employees who earn a salary more than a the minimum salary
SELECT *
FROM Employee
WHERE salary > (SELECT MIN(salary) FROM Employee);
List the managers who have more than 2 employees reporting them
SELECT Cassette.*
FROM Iss_rec, Cassette
WHERE Iss_rec.cass_no = Cassette.cass_no
AND Iss_rec.iss_date BETWEEN '2022-01-01' AND
'2022-02-29';
List the details of customers who has not borrowed any cassette
SELECT *
FROM Customer
WHERE cust_no NOT IN (SELECT cust_no FROM Iss_rec);
Create a view ADULT with the details of customers who born after 2004
SELECT *
FROM Employee
WHERE designation LIKE '%Assistant%';
SELECT *
FROM Employee
WHERE salary = (SELECT MAX(salary) FROM Employee);
Display the details of employees who work in more than 2 projects
SELECT E.*
FROM Employee E, Project P
WHERE E.id = P.emp_id
GROUP BY E.id
HAVING COUNT(P.proj_id) > 2;
UPDATE Employee
SET salary = salary * 1.1;
SELECT *
FROM Movie
WHERE YEAR(date_of_release) = 1950;
List the “Comedy” movies in Tamil language
List the movie ids that are rated 3 and above by “Ajay”
SELECT R.movie_id
FROM Rating R, Reviewer RV
WHERE R.reviewer_id = RV.id
AND RV.name = 'Ajay'
AND R.stars >= 3;
SELECT title
FROM Movie, Genre
WHERE Movie.genre_id = Genre.id
AND Genre.type = 'Thriller';
SELECT *
FROM Customer
WHERE city = 'Chennai';
UPDATE Salesman
SET commission = commission * 1.02
WHERE city = 'Kanchi';
Find all the customers along with the salesperson who works for them.
Find the sales people who has not done any order
SELECT S.*
FROM Salesman S
WHERE S.SID NOT IN (SELECT DISTINCT SID FROM Orders
WHERE SID IS NOT NULL);
List the orders made between 25th December 2021 and 1st Jan 2022
SELECT *
FROM Orders
WHERE order_date BETWEEN '2021-12-25' AND '2022-01-
01';
Find those orders where order amount exists between 500 and 2000. Return
ord_no, purch_amt, cust_name, city.
G) Salesman (SID int, name: string, city string, commission float, DOJ date)
Customer (CID int, name string, city string, SID int)
Orders(OrderNo int, Pur_amount float, order_date date, CID int, SID int)
UPDATE Salesman
SET commission = commission * 1.05
WHERE city = 'Vellore';
SELECT O.*
FROM Orders O, Customer C, Salesman S
WHERE O.CID = C.CID
AND O.SID = S.SID
AND C.city = 'Chennai'
AND O.Pur_amount > 100000
AND MONTH(O.order_date) = 10
AND YEAR(O.order_date) = 2023;
List the salesman who do not have any customer
SELECT S.*
FROM Salesman S
WHERE S.SID NOT IN (SELECT SID FROM Customer WHERE
SID IS NOT NULL);
SELECT *
FROM Employee
WHERE YEAR(DOJ) = YEAR(NOW());
List the employees who earn a salary equal to the average salary
SELECT *FROM Employee
WHERE salary = (SELECT AVG(salary) FROM Employee);
List the employees who work in same job_id for more than an year
SELECT E1.*
FROM Employee E1, Employee E2
WHERE E1.job_id = E2.job_id
AND E1.DOJ - E2.DOJ > 365;