Deep
Deep
Database changed
NAME VARCHAR(50),
SALARY INT,
DEPTID INT
(335, 'Henry', 43000, 40), (400, 'Rachel', 115600, 10), (441, 'Peter', 58200, 20);
DEPARTMENT VARCHAR(50),
CITY VARCHAR(50)
mysql> Inserting data into the Dept_Deep table mysql> INSERT INTO Dept_Deep
(DEPTID, DEPARTMENT, CITY) VALUES (10, 'MARKETING', 'NEW DELHI'), (20, 'FINANCE',
'GURUGRAM'), (30, 'SALES', 'NOIDA'),
Q2. Name of columns which act as primary key and foreign key in tables Emp and Dept
GROUP BY DEPTID;
GROUP BY DEPTID;
Q5. To display the maximum salary and minimum salary in each department.
GROUP BY DEPTID;
Student & Stream Table
mysql> use Deepjain
Database changed
Stream CHAR(20),
Location CHAR(50));
Ad_No INT(2),
First_Name CHAR(50),
Last_Name CHAR(50),
Section CHAR(I),
s_lD INT(2),
->Date_Of_Birth DATE,
mysql> Q4) Display the details of all the students with less than 60 percentage
mysql> Q5) Display the Ad_No and First_Name of the students who were born after 01/01/2007
mysql> Q6) Display the details of the students who were born before 2007
mysql> Q8) Display the details of all the students whose percentage is not NULL
mysql> Q9 & QIO) Display the various sections of the students, each section appearing only once
mysql> QII) Display the details of all the students born after 2006 and have a percentage of more
than
50
mysql> SELECT * FROM student_Deep WHERE > '2006-12-31' AND Percentage > 50;
mysql> Q12) Display the First_Name and Percentage of all the students whose section is not 'A'
WHERE Section
mysql> — Q13) Display the First_Name and Section of all the students whose percentage is less than
70 or whose S ID is 10
mysql> SELECT *
mysql> — Q15) Display the details of all the students whose percentage is in the range of 50 to 70
mysql> SELECT *
mysql> — Q16) Display all the details of the students whose DOB is 2007 and class is 11
mysql> Q17) Display the First_Name and Class for all the students whose section is 'A' or 'B'
mysql> SELECT *
mysql> Q19) Display the details of all the students who were born between 2006 and 2007 mysql>
SELECT *
mysql> Q20) Display the Ad_No, First_Name, and Section of all the students for which the Last_Name
ends with 'Kumar'
mysql>
SELECT Ad_No, First_Name, Section FROM student_Deep WHERE Last_Name LIKE '%Kumar';
mysql> Q21) Display the Ad_No, First_Name, and Section for all the students for which the
First_Name ends with 'a'
mysql> SELECT Ad_No, First_Name, Section FROM student_Deep WHERE First_Name LIKE '%a';
mysql> Q22) Display the Ad_No and First_Name from all the students which contains 'a'
mysql> SELECT Ad_No, First_Name FROM student_Deep WHERE First_Name LIKE '%a%';
mysql> Q23) Display the Ad_No and First_Name from all the students for which the First_Name does
not contain 'e'
mysql> SELECT Ad_No, First_Name FROM student_Deep WHERE First_Name NOT LIKE '%e%';
mysql> Q24) Display the Ad_No and First_Name from all the students for which the First_Name
contains 'a' as the second last character
mysql> SELECT Ad_No, First_Name FROM student_Deep WHERE First_Name LIKE '%a_',
mysql> Q25) Display the details of all the students in ascending order of their Percentage
mysql> Q26) Display the details of all the students in descending order of their Date_Of_Birth
mysql> Q29) Increase the percentage by 2 for all the students whose Section is 'C'
mysql> Q31) Delete all the records of the student named 'Tushar' mysql>
mysql> Q32) Add another column Phone_NO of type INT() in the student table
Group By Functions
mysql> QI) Display First Name, Class, Section, Location, DOB, and Stream from each student where
stream contains "c" character and DOB is less than 2008.
GROUP BY Stream;
mysql> Q3) Display max (Percentage), min (Percentage), count(*), count(Last_Name), avg (Percentage),
sum (Percentage) in each section.
mysql> SELECT Section,
mysql>
-> MAX(Percentage), MIN(Percentage), COUNT(*), COUNT(Last_Name), AVG (Percentage),
SUM(Percentage)
GROUP BY Section;
mysql> Q4) Display the number of students in each stream with percentage between 50 to 70.
GROUP BY Stream;
mysql> Q5) Display the number of students in each stream where the number is greater than 5.
GROUP BY Stream
mysql> Q6) Display the number of students in each stream where percentage is greater than 60 and
the number of streams is greater than 2.
GROUP BY Stream
Numeric Functions
mysql> Q8) Round off the percentage to zero decimal places.
mysql> Q9) Display 23472.162738 up to 4 decimal places. mysql> SELECT ROUND (23472.162738, 4);
mysql> QIO) Display 23472.162538 up to the nearest ten's place. mysql> SELECT ROUND
(23472.162538, -1);
mysql>
Date Functions
Q12) Display day from DOB in student table.
mysql> Q14) Display week from DOB in student table. mysql> SELECT Ad_No, First_Name,
WEEK(Date_Of_Birth) FROM student_Deep;
mysql> Q15) Display day name from DOB in student table. mysql> SELECT Ad_No, First_Name,
DAYNAME(Date_Of_Birth) FROM student_Deep; mysql> Q16) Display month from
DOB in student table.
mysql>SELECT Ad_No,First_Name ,
MONTHNAME(Date_Of
_Birth) AS Month_Name FROM student Deep;
mysql> Q18) Display the First_Name of the student who was born on "Tuesday".
mysql>
Q19) Display the student information whose DOB is between 2007 and 2008.
mysql> SELECT *
FROM student Deep-> WHERE Date Of Birth BETWEEN '2007-01-01' AND '2008-12- 31';
mysql> Q20) Display the First_Name, Last_Name, and Percentage of the student who was born in
January.
mysql> Q21) Display the student information who was born in week 1.
mysql>
String Function
Q22) Display First_Name in upper case and Last_Name in lower case and merge them.
mysql> Q23) Display all characters in First_Name from the 3rd position.
mysql> Q24) Display number of characters in Last_Name where percentage is greater than 70 and
First Name contains "l".
mysql>
mysql>
Cartesian Functions
Q29: Cartesian product to display all records of stream and student tables.
mysql> Q30: Display the number of columns (Degree) of student, stream, and Cartesian product
tables.
FROM stream Deep • mysql> Display the number of columns (Degree) of the Cartesian product
mysql> Q31: Display the number of rows (Cardinality) of student, stream, and Cartesian product.
mysql>
mysql> SELECT
Join Function
Q32) Display all the records from stream and student table.
mysql>
mysql> Q33) Display student name and their stream (like ART, COMMERCE, SCIENCE) from student
and stream table.
mysql> Q34) Display the number of students in each stream (like ART, COMMERCE, SCIENCE) from
student and stream table.
mysql> Q35) Display the number of students in each stream having percentage more than 50 and
number of records should be higher than 3 (like ART, COMMERCE, SCIENCE) from student and
stream table.
FROM student
GROUP BY Stream
HAVING COUNT(*)> 3;