PGDCA 106 LabPractice2 SQL2
PGDCA 106 LabPractice2 SQL2
SELECT column_list
FROM table_name
WHERE condition
Q #22 ) Display the name, gender and date of births of all students who were born after 31-
December-2000.
SELECT name, gender, dob FROM student WHERE dob > ‘2000-12-31’
Q #23) Display the name, dob, doj and salary of all employees who draws salary less than 20,000
SELECT name, dob, doj, salaray FROM employee WHERE salary < 20000
Q #25 ) Display the names of all students whose name contains the alphabet ‘s’
SELECT name FROM student WHERE name LIKE ‘%s%’
Q #26 ) Display the name, gender and date of births of all students who were born in the years 2000
and 2001.
SELECT name, gender, dob
FROM student
WHERE year(dob) IN (2000,2001)
Q #27) Display the name, dob, doj and salary of all employees who have joined in the months
‘January’, ‘February’ or ‘March’
SELECT name, dob, doj, salaray
FROM employee
WHERE month(doj) IN (‘January’, ‘February’, ‘March’)
Q #29) Display the name, dob, doj and salary of all employees who have joined in the months
‘January’, ‘February’ or ‘March’
PGDCA 106 Lab Practice - 2 (PC Skills & Database) Part III: SQL
SELECT name, dob, doj, salaray
FROM employee
WHERE month(doj) = ‘January’
OR month(doj) = ‘February’
OR month(doj) = ‘March’
Q #30 ) Display the name, gender and date of births of all ‘Female’ students who were born after
31-December-2000.
SELECT name, gender, dob
FROM student
WHERE gender = ‘female’
AND dob > ‘2000-12-31’
Q #31) Display the name, dob, doj and salary of all employees who joined after ‘31-December-2020
and draws salary greater than 25,000
SELECT name, dob, doj, salaray
FROM employee
WHERE doj > ‘2020-12-31’
AND salary > 25000
Q #32 ) Display the name, gender and date of births of all students who were born after 31-
December-2000 and before 01-January-2002.
SELECT name, gender, dob
FROM student
WHERE dob > ‘2000-12-31’
AND dob < ‘2002-01-01’
Q #33) Display the name, dob, doj and salary of all employees who draws salary greater than
20,000 and less than 30,000
SELECT name, dob, doj, salaray
FROM employee
WHERE salary > 20000
AND salary < 30000
Q #35 ) Display the names of all students whose class or mark is not specified
SELECT name FROM student WHERE class IS NULL OR mark IS NULL
Q #37 ) Display the names of all students who have completed 18 years
SELECT name FROM student
WHERE datediff(curdate(), dob)/365.25 > 18
Q #38) Display the name, dob, doj and salary of all employees who got job before they complete 22
years
SELECT name, dob, doj, salaray
PGDCA 106 Lab Practice - 2 (PC Skills & Database) Part III: SQL
FROM employee
WHERE datediff(doj, dob) < 22 * 365.25
Q #39) Display the name, dob, doj, salary, and date of retirement (last day of the month in which
they complete 60 years) of all employees
SELECT name, dob, doj, salaray,
LAST_DAY(DATE_ADD(dob, INTERVAL 1 YEAR)
FROM employee
Q #40 ) Display the details of all students who were born on the last day of the month in which they
were born
SELECT * FROM student WHERE day(dob) = day(last_day(dob))
Q #42 ) Delete all rows of student in the class ‘C1’ from the student table
DELETE FROM student WHERE class = ‘C1’
Q #43 ) Delete all employees who joined before ‘01-January-1970’ in the employee table
DELETE FROM employee WHERE doj < ‘1970-01-01’
The SQL statement DROP TABLE is used for deleting or removing the tables stored in an SQL
compliant RDBMS. This statement will permanently remove both the data and its structure/skeleton
from the datatbase.
DROP TABLE statement will remove a table from the database where as DELETE statement will
only remove some/all rows from a table.
Q #45 ) Display the employee names and department names of all employees
SELECT employee.name, departments.name
FROM employee, department
WHERE employee.department_code = department.code
Q #47 ) Create a view containing the classes, number of students, average mark
SELECT class, COUNT(name), AVG(mark)
FROM student
GROUP BY class
Q #48 ) Create a view with name, gender and date of births of all students who were born after 31-
December-2000.
CREATE VIEW studentsabove21 AS
SELECT name, gender, dob FROM student WHERE dob > ‘2000-12-31’
Q #49) Create a view with name, dob, doj and salary of all employees who draws salary less than
20,000
CREATE VIEW employee2 AS
SELECT name, dob, doj, salaray FROM employee WHERE salary < 20000
SELECT column_list
FROM table_name
WHERE condition
ORDER BY column_name ASCENDING|DESCENDING
Q #50 ) Display the details of all students in class ‘C1’ in the order of their age
SELECT * FROM student WHERE class = ‘C1’ ORDER BY dob DESC
PGDCA 106 Lab Practice - 2 (PC Skills & Database) Part III: SQL
Q #51 ) Display the gender, age and names of all students in class ‘C1’ in the order of gender and
descending order of age
SELECT gender, date_diff(curdate(), dob)/365.25 as age, name
FROM student
WHERE class = ‘C1’
ORDER BY gender, dob
Q #56 ) Display the class, number of students, maximum and minimum marks of all students
SELECT class, COUNT(name), MAX(mark), MIN(mark)
FROM student
Q #57) Display the salary, and number of employees drawing that salary
SELECT salary, COUNT(name)
FROM employee
SELECT column_list
FROM table_name
WHERE condition
GROUP BY column_name
HAVING condition
ORDER BY column_name ASCENDING|DESCENDING
Q #58 ) Display the class and class average of those class class with class average >= 60
SELECT class, AVG(mark)
FROM student
GROUP BY class
HAVING AVG(class) >= 60
Q #59 ) Display the name, gender and date of birth of the youngest student.
SELECT name, gender, dob
FROM student
WHERE dob = (SELECT MIN(dob) FROM student)
Q #60) Display the name, dob, doj and salary of all employees who draws the highest salary
SELECT name, dob, doj, salaray
FROM employee
WHERE salary = (SELECT MAX(salary) FROM employee)