0% found this document useful (0 votes)
39 views

Dinesh IT File

Uploaded by

kumarsaabpb06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Dinesh IT File

Uploaded by

kumarsaabpb06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 36

PRACTICAL No.

- 1
i) Create a student table with the student id, name, and
marks as attributes where the student id is the primary key.

Solution:
Source
Code:
create table student
(
-> studid int primary key,
-> name varchar(30),
-> marks int -
>
);

Screenshot:

ii) In the table ‘student’ created in practical 26, insert the details of
new students.

Solution:
Source
Code:
insert into student values(1, 'sanjay', 67);
mysql> insert into student values(2, 'surendra', 88);
mysql> insert into studen values(3, 'Jamil', 74);
mysql> insert into t values(4, 'Rahul', 92)
studen
t
mysql> insert into student values(5, 'Prakash', 78);

Screenshot

1
iii) Write SQL command to get the details of the students with
marks more than 80.

Solution
: Source
Code:
select * from student where marks >=80;

Screenshot:

iv) Write SQL command to Find the min, max, sum, and average
of the marks in a student marks table..

Solution:
Source
Code:
select min(marks) as Min_marks, max(marks) as Max_Marks, sum(marks)
as Total_Marks, avg(marks) as Average_Marks from student;

Screenshot:

2
PRACTICAL No. -2
TABLE-INFO

i) Write a Query to display all the details of the


Employees from the above table 'INFO'.
Solution :
Source Code :

SELECT * FROM INFO;

Screenshot :

ii) Write a Query to Display Employees’ name and


City from the above table
Solution :
Source Code :

SELECT NAME, CITY FROM INFO;

3
Screenshot :

iii) Write a Query to Display all details of Employees


who are living in Chennai
Solution :
Source Code :

SELECT * FROM INFO WHERE CITY='CHENNAI';


Screenshot :

iv) Write a Query to get the name and salary of the


employee whose salary is above 15000 and gender
is not male
Solution :
Source Code :

SELECT NAME,SALARY FROM INFO WHERE SALARY


>15000 AND GENDER<>'M';

Screensh

4
PRACTICAL No. -3
TABLE-STU

i) Write a Query to display Department name in lower


case letters.

Solution :
Source Code :

SELECT LCASE(DEPT) FROM STU;

Screenshot :

ii) Write a Query to display department name and its


respective number of characters in Dept column.

Solution :
Source Code :

SELECT DEPT,LENGTH(DEPT) FROM STU;

5
Screenshot :

iii) Write a Query to display first 2 characters of the


column Name.

Solution :
Source Code :

SELECT LEFT(NAME,2) FROM STU;

Screenshot :

iv) Write a query to display the names of all students and


extract five characters from the third position of the
'Name' field.

Solution :
Source Code :

6
SELECT SUBSTR(NAME,3,5) FROM STU;

Screenshot :

7
PRACTICAL No. - 4
TABLE-Nurse

i) Retrieve all nurses who are not registered

Solution :
Source Code :

SELECT * FROM nurse WHERE registered = 'f';

Screenshot :

ii) Search by Name

Solution :
Source Code :

SELECT * FROM nurse WHERE name = 'Carla Espinosa';

Screenshot :

8
iii) Get Distinct Nurse Positions

Solution :
Source Code :

SELECT DISTINCT position FROM nurse;

Screenshot :

iv) Find Nurses with SSNs Ending in ‘0’

Solution :
Source Code :

SELECT * FROM nurse WHERE ssn LIKE '%0';

Screenshot :

9
PRACTICAL No. - 5
TABLE- States

i) Find States with Population Over 20 Million

Solution :
Source Code :

SELECT * FROM States WHERE population > 20000000;

Screenshot :

ii) Order States by Area (Largest to Smallest)

10
Solution :
Source Code :

SELECT * FROM States ORDER BY area DESC;


Screenshot :

iii) Search for States with Specific Capital Names

Solution :
Source Code :

SELECT * FROM States WHERE capital LIKE '%City%';


Screenshot :

iv) Calculate Average Population

Solution :
Source Code :

SELECT AVG(population) AS avg_population FROM States;


Screenshot:

11
PRACTICAL No. - 6
TABLE- Teacher

i) Sort teachers by name in alphabetical order

Solution :
Source Code :

SELECT * FROM Teachers ORDER BY teacher_name


Screenshot:

ii) List teachers who teach a specific subject (e.g., ‘Mathematics’)

Solution :
12
Source Code :

SELECT * FROM Teachers WHERE subject_taught = 'Mathematics';


Screenshot:

iii) Find the teacher with the longest name

Solution :
Source Code :

SELECT * FROM Teachers ORDER BY LENGTH(teacher_name) DESC LIMIT 1;


Screenshot:

iv) Update a teacher’s subject (e.g., change subject_taught for teacher_id


= 205)

Solution :
Source Code :

UPDATE Teachers SET subject_taught = 'Political Science' WHERE teacher_id =


204;
Screenshot:

13
PRACTICAL No. - 7
TABLE- Students_2

i) Retrieve Students Older Than 20

Solution :
Source Code :

SELECT * FROM Students_2 WHERE Age > 20;

Screenshot:

ii) Count the Number of Students


14
Solution :
Source Code :

SELECT COUNT(*) AS TotalStudents FROM Students_2;


Screenshot:

iii) Update Frank’s Grade to ‘C’


Solution :
Source Code :

UPDATE Students_2 SET Grade = 'C' WHERE Name = 'Frank';

Screenshot:

iv) Calculate Average Age of Students:

Solution :
Source Code :

SELECT AVG(Age) AS AvgAge FROM Students_2;


Screenshot:

15
PRACTICAL No. - 8
TABLE- Employee

i) to display ECODE column as EMPLOYEE_CODE in output

Solution :
Source Code :

SELECT ECODE AS ‘EMPLOYEE_CODE’ FROM EMPLOYEE ;

Screenshot

16
ii) to display ECODE, ENAME and GRADE of those
employees whose salary is between 40000 and 50000

Solution :
Source Code :

SELECT ECODE , ENAME ,GRADE FROM EMPLOYEE WHERE


GROSS BETWEEN 40000 AND 50000 ;

Screenshot

iii) to display names of employee whose name starts with


R in EMPLOYEE table,
Solution :
Source Code :

SELECT ENAME FROM EMPLOYEE WHERE ENAME LIKE “R%” ;

Screenshot

iv) to remove the details of those employee from


EMPLOYEE table whose grade is A1.

17
Solution :
Source Code :

DELETE FROM EMPLOYEE WHERE GRADE =’A1’ ;


Screenshot

PRACTICAL No. – 9
TABLE- STOCK

TABLE- DEALERS

i) To display the total Unit price of all the products whose


Dcode as 102.

Solution :
Source Code :

SELECT SUM(UNITPRICE) FROM STOCK GROUP BY DCODE


HAVING DCODE=102;

18
Screenshot

ii) To display details of all products in the stock table in


descending order of Stock date.

Solution :
Source Code :

SELECT * FROM STOCK ORDER BY STOCKDATE DESC;

Screenshot

iii) To display maximum unit price of products for each


dealer individually as per dcode from the table Stock.

Solution :
Source Code :

SELECT * FROM STOCK ORDER BY STOCKDATE DESC;

Screenshot

19
iv) To display the Pname and Dname from table stock and
dealers.

Solution :
Source Code :

SELECT PNAME,DNAME FROM STOCK S,DEALERS D WHERE


S.DCODE=D.DCODE;

Screenshot

20
PRACTICAL No. – 10
TABLE- CRICKET

i) Create table ‘CRICKET’

Solution :
Source Code :

CREATE TABLE cricket


-> (
-> id_no int,
-> name int,
-> score varchar(50),
-> goals int
-> );

Screenshot

ii) Change name of column id_no to jersey_no

Solution :
Source Code :

ALTER TABLE cricket CHANGE id_NO jersey_no int;

21
Screenshot

iii) Assign Primary Key to Jersey_no

Solution :
Source Code :

ALTER TABLE cricket ADD PRIMARY KEY (jersey_no);

Screenshot

iv) To Add a new column Country

Solution :
Source Code :

ALTER TABLE cricket ADD COLUMN country varchar(50);

Screenshot

22
PRACTICAL No. – 11
TABLE- SMARKS

i) To create Table ‘smarks’

Solution :
Source Code :

CREATE TABLE smarks (rank int auto_increment primary key,


name char(50), sub1 int, sub2 int, sub3 int, total int,
percentage double(4,2));

Screenshot

ii) To insert records in ‘smarks’

Solution :
Source Code :

CREATE TABLE smarks (rank int auto_increment primary key,


name char(50), sub1 int, sub2 int, sub3 int, total int,
percentage double(4,2));

23
Screenshot

iii) To Manipulate the Table ‘smarks’

Solution :
Source Code :

UPDATE smarks SET total = (sub1+sub2+sub3);


UPDATE smarks SET percentage = total/3;
Screenshot

iv) To view the whole table ‘smarks’

Solution :
Source Code :

SELECT * FROM smarks;


Screenshot

24
PRACTICAL No. – 12
TABLE- Movies

i) Display the type of movies.

Solution :
Source Code :

select distinct from a movie;

Screenshot

25
ii) Display movieid, moviename, total_eraning by showing
the business done by the movies. Claculate the
business done by movie using the sum of
productioncost and businesscost.

Solution :
Source Code :

select movieid, moviename, productioncost + businesscost


“total earning” from movie;

Screenshot

iii) Display the movie of type action and romance.

Solution :
Source Code :

select moviename from movie where type =’action’ or


type=’romance’;

26
Screenshot

iv) Display the list of movies which are going to release in


February, 2022.

Solution :
Source Code :

select moviename from moview where month(releasedate)=2;

Screenshot

27
PRACTICAL No. -13

TABLE- INFO
Refer to The Table of Practical no. – 2

i) Write a query to update increase 10% Salary of an


employee whose City is 'CHENNAI' and Gender is
'MALE'.

Solution :
Source Code :

UPDATE INFO SET SALARY=SALARY+ (SALARY*0.10) WHERE


CITY='CHENNAI' AND GENDER='M';

Screenshot

28
ii) Write a Query to delete the details of Employee Id 6.

Solution :
Source Code :

DELETE FROM INFO WHERE EMPID=6;

Screenshot

iii) To Count employees in Sales department

Solution :
Source Code :

SELECT COUNT(EmpID) FROM Employees WHERE Dept =


'Sales';

Screenshot

iv) To Find highest salary:

Solution :
Source Code :

SELECT MAX(Salary) AS HighestSalary FROM Employees;

Screenshot

29
PRACTICAL No. – 14

TABLE-STU
Refer to The Table of Practical no. – 2

i) to Display square of age that got admission in the


month of August

Solution :
Source Code :

SELECT POWER(AGE,2) FROM STU WHERE DOA LIKE '%-08-%';

Screenshot

30
ii) to display Remainder of column Percentage divide by 3.

Solution :
Source Code :

SELECT MOD(MARKS,3) FROM STU;

Screenshot

iii) to display Student names and their Percentage in round


figure

Solution :
Source Code :

SELECT NAME, ROUND(PERCENTAGE,0) FROM STU;

Screenshot

iv) to display Department name in lower case letters.

31
Solution :
Source Code :

SELECT LCASE(DEPT) FROM STU;

Screenshot

PRACTICAL No. – 15

TABLE-Phone

i) To Update Price for ‘POCO CE’

Solution :
Source Code :

32
UPDATE table_name SET price = '15000' WHERE name =
'POCO CE';

Screenshot

ii) To Insert New Record (‘86153603019603’, ‘OnePlus 9’, ‘30000’):

Solution :
Source Code :

INSERT INTO phone (Imei, name, price) VALUES


('86153603019603', 'OnePlus 9', '30000');

Screenshot

iii) TO Sort by Price (Descending)

Solution :
Source Code :

SELECT * FROM phone ORDER BY price DESC;

Screenshot

iv) To Calculate Average Price:

33
Solution :
Source Code :

SELECT AVG(price) FROM phone;

Screenshot

PRACTICAL No. – 16

TABLE-SMARKS
Refer to The Table of Practical no. – 11

i) TO display all the Records of krishna.

Solution :
Source Code :

SELECT * FROM smarks WHERE name = ‘Krishna’;

Screenshot

34
ii) To display all the record of students except krishna

Solution :
Source Code :

SELECT * FROM smarks WHERE NOT name = ‘Krishna’;

Screenshot

iii) To display Max percentage

Solution :
Source Code :

SELECT MAX(percentage) MAX FROM smarks;

Screenshot

35
iv) To display the name of studemt obtaining rank = 1 in caps

Solution :
Source Code :

SELECT UPPER(name) NAME FROM smarks WHERE rank = 1;

Screenshot

36

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy