Professional Documents
Culture Documents
4 Viva 3
Total 15
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 80.
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 frist 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 sidesfrom the text – ” Informatics Practices Class XII “.
11. Display today’s date in “Date/Month/Year” format.
12. Display dayname, monthname, day, dayname, day of month, day of year for today’s date.
Answers
Table data:
[6] Group by
select country, count(customer_id) from customer group by country;
[7] Sorting in descending order
select * from student order by marks desc;
[12]
select
dayname(now()),monthname(now()),day(now()),dayname(now()),dayofmonth(now()),dayofyear(now());
TABLE-2
1. Create a database named PracticalExam and open database. 1
2. Create following table – “Candidate” 1
candidateid – int(4), Primary Key
candidatename – varchar(20) not null
batch – varchar(10)
examdate – date
marks – float
stream – varchar
3. Insert 10 records into the table as per your choice, one sample is as following (Use batches as: Batch1, Batch2,
Batch3) : 1
1201, ‘Sagar Patel’, ‘Batch1’, ‘2022/02/25’, 14, ‘commerce’
4. Write queries based on the table candidate 4
Dispay the square of marks for candidates
Display candidateid, cadnidatename, examdate, marks without decimalplaces for batch1 and batch2
students
Display maximum, minimum and sum of marks of candidates
Display number students from commerce stream
Display the candidate names into capitals
Display first two letters of candidatenames
Display the average marks of stduents for each batch
Display the name of the day of week including candidatename, batch, marks and stream
Solution
create database practicalexam
use practicalexam;
create table candidate
(candidateid int(4) primary key,
candidatename varchar(20) not null,
batch varchar(10),
examdate date,
mark float,
stream varchar(10));
insert into candidate values
(1201,'Sagar Patel','Batch 1','2022/02/25',14.5,'commerce'),
(1202,'Smita Patel','Batch 2','2022/02/24',13.5,'science'),
(1203,'Aman Parmar','Batch 3','2022/02/20',12,'commerce'),
(1204,'Sapna Vyas','Batch 2','2022/02/25',10.5,'science'),
(1205,'Man Pandya','Batch 1','2022/02/24',11,'commerce'),
(1206,'Dinesh Parmar','Batch 2','2022/02/25',14,'commerce'),
(1207,'Sonam Solanki','Batch 1','2022/02/25',13,'science'),
(1208,'Manish Joshi','Batch 2','2022/02/23',14.5,'commerce'),
(1209,'Mahendra Gohel','Batch 1','2022/02/25',14,'commerce'),
(1210,'Smita Chava','Batch 3','2022/02/25',15,'science');
Queries:
Consider the following tables Employee22 and Department and answer the given questions?
Employee 22