G12 Practical Questions (2ndterm)
G12 Practical Questions (2ndterm)
MYSQL Commands
Lab Record 1
Table: student
1. Create a student table with the student id, name, and marks as attributes where the
student id is the primary key.
2. Insert the details of a new student in the above table.
3. Delete the details of a student in the above table.
4. Use the select command to get the details of the students with marks more than 75.
5. Find the min, max, sum, and average of the marks in a student marks table.
6. Find the total number of customers from each country in the table (customer ID,
customer
Name, country) using group by.
7. Write a SQL query to order the (student ID, marks) table in descending order of the
marks
8. Write a SQL query to display the marks without decimal places, display the reminder
after diving marks by 3 and display the square of marks
9. Write a SQL query to display names into capital letters, small letters, display first 3
letters of name, display last 3 letters of name, display the position the letter A in
name
10.Remove extra spaces from left, right and both sides from the text – ” Informatics
Practices Class XII “.
11.Display today’s date in “Date/Month/Year” format.
12.Display dayname, month name, day, dayname, day of month, day of year for today’s
date.
Answers
marks decimal(5,2));
Q2) Inserting records
Table data:
Q3) Deleting records
Q6) Group by
select ltrim(" Informatics Practices Class XII ") "Left Trim", rtrim("
Informatics Practices Class XII ") "Right Trim", trim(" Informatics
Practices Class XII ") “Both”;
select
dayname(now()),monthname(now()),day(now()),dayname(now()),dayofmonth(now
()),dayofyear(now());
Lab Record 2
Table: Teacher
1) Create a teacher table with the T_ID, Name, Age, Gender, Department,
Date_of_join, Salary and Post as attributes where the T_ID is the primary key.
2) Insert the details of a new teacher in the above table.
3) Delete the details of a teacher in the above table.
4) To display all information of TGT teachers.
5) To display the name, post and salary of all teachers in ascending order of their
salaries.
6) To display the total salary of teachers who are in the same post.
7) To display teacher’s name in which ‘ee’ occurs anywhere in the name.
8) To display contents of “Department” field in small letters.
9) To display first 2 characters of the “Department” field.
10) To display 3 characters of teacher’s name starting from 2nd Character.
11) To display the name, age and joining date of teachers who joined in May Month.
12) To display the name and salary of teacher’s after rounding off to the nearest
integer.
13) To display the department name and no of teachers in each department.
14) To display the maximum and minimum date of join of teachers.
15) To display the average salary of male teachers from the table.
Answers:
Post char(3));
Table: Employee
1) Create an Employee table with the EMPNO, ENAME, JOB, MGR, HIREDATE,
Sal, comm and DEPTNO as attributes where the EMPNO is the primary key.
2) Insert the details of a new employee in the above table.
3) Delete the details of an employee in the above table.
4) Write a query to get the details of all employees according to name in descending
order.
5) Write a query to get unique department number from employee table.
6) Write a query to get the total salaries payable to employees who joined in
February month.
7) Write a query to subtract the maximum and minimum salary from employee
table.
8) To display first three characters extracted from jobs of employees 8499 and 8654.
9) To display the position string ‘le’ in the field Job of employee table.
10) To display employee names and the name-lengths for employees 8566 and 8369.
11) To display the maximum, minimum and average salary of employees grouped by
department number.
12) To display the joining date of senior most employee.
13) To display average salary of employees with DEPTNO 20 or 30.
14) To display the number of employees with the same job
15) To display the difference of highest and lowest salary of each department having
maximum salary>1500.
Q1) Create table
Table data