mysql_record_continue
TRANSCRIPT
Table :: EMPL
Q1. Write a query to display Ename and Sal of employees whose salary is greater than or equal
to 2200 from table Empl?
empno Ename Job mgr hiredate sal comm deptno
8369 SMITH CLERK 89021990-12-
18800.00 NULL 20
8499 ANYA SALESMAN 86981991-02-
20
1600.0
0300.00 30
8521 SETH SALESMAN 86981991-02-
22
1250.0
0500.00 30
8566 MAHADEVAN MANAGER 88391991-04-
02
2985.0
0NULL 20
8654 MOMIN SALESMAN 86981991-09-
28
1250.0
0
1400.0
030
8698 BINA MANAGER 88391991-05-
01
2850.0
0NULL 30
8882 SHIAVNSH MANAGER 88391991-06-
09
2450.0
0NULL 10
8888 SCOTT ANALYST 85661992-12-
09
3000.0
0NULL 20
8839 AMIR PRESIDENT NULL1991-11-
18
5000.0
0NULL 10
8844 KULDEEP SALESMAN 86981991-09-
08
1500.0
00.00 30
8886 ANOOP CLERK 88881993-01-
12
1100.0
0NULL 20
8900 JATIN CLERK 86981991-12-
03950.00 NULL 30
8902 FAKIR ANALYST 85661991-12-
03
3000.0
0NULL 20
8934 MITA CLERK 88821992-01-
23
1300.0
0NULL 10
mysql > select ename,sal from empl where sal > = 2200 ;
Q2. Write a query to display details of employees who are not getting commission from table
empl?
mysql > select * from empl where ( comm is null || comm = 0.00) ;
Q3. Write a query to display employee name and salary of those employee who don’t have there
salary in the range of 2500 to 4000?
mysql > select ename, sal from empl where sal not between 2500 and 4000 ;
Q4. Write a query to display the name, job title and salary of employee who do not have
manager?
mysql > select ename, job, sal from empl where mgr is null ;
Q5. Write a query to display the name of the employee whose name contains ‘A’ as third
alphabet?
mysql > select ename from empl where ename like '_ _A% ;
Q6. Write a query to display the name of the employee whose name contains ‘T’ as last
alphabet?
mysql > select ename from empl where ename like '%T' ;
Q7. Write a query to display the name of the employee whose name contains ‘M ‘ as first
alphabet ‘L’ as third alphabet?
mysql > select ename from empl where ename like 'M_L%' ;
Q8. Write a query against the empl table to show the names of all employees concatenated with
their job type.
mysql > select concat(ename, job) from empl ;
Q9. Give commission of Rs. 500 to all employees who joined in year 1982
mysql > update empl set comm=500 where hiredate like '1982-%' ;
1
Q10. Modify tables Empl, add another column called Grade of VARCHAR type, size 1 into it
mysql > alter table empl add grade varchar(1) ;
Q11. In the added column Grade, assign grades as follows:
if sal is in the range 700 – 1500, Grade is 1
mysql > update empl set grade=1 where sal between 700 and 1500 ;
if sal is in the range 1500 – 2200, Grade is 2
mysql > update empl set grade=2 where sal between 1500 and 2200 ;
if sal is in the range 2200 – 3000, Grade is 3
mysql > update empl set grade=3 where sal between 2200 and 3000 ;
if sal is in the range 3000, Grade is 4
mysql > update empl set grade=4 where sal >=3000 ;
Q12. Add a constraint (NN-Grade) in the table Empl that declares column Grade not null
mysql > alter table empl modify grade varchar(1) not null ;
Q13. Insert a record of your choice in table Empl. Make sure not to enter Grade
mysql > insert into empl values(1,’lakshmi’,’teacher’,1111,’2009-11-16’,14000,null,101,null) ;
Error : Column ‘grade’ cannot be null
Q14. Increase salary of employee records by 10%
mysql > update empl set sal = sal + ( sal * 0.1 ) ;
Q15. Modify the definition of column Grade. Increase its size to 2.
mysql > alter table empl modify grade varchar(2) ;
Q16. Drop the table Empl
mysql > drop table empl ;
2
Table :: STUDENT
StudentN
oClass Name GAME Grade1 SUPW Grade2
10 7 Sameer Cricket B Photography A
11 8 Sujit Tennis A Gardening C
12 7 Kamal Swimming B Photography B
13 7 Veena Tennis C Cooking A
14 9 Archana Basket Ball A Literature A
15 10 Arpit Cricket A Gardening C
1Q. Display the names of the students who are getting a grade ‘C’ in either Games or SUPW
mysql > select name from student where grade1='C' || grade2='C';
2Q. Display the different games offered in the school
mysql > select distinct(game)from student;3
3Q. Display the SUPW taken up by the students, whose name start with ‘A’
mysql > select supw from student where name like 'A%';
4Q. Display the names of the students who are getting a grade ‘C’ in either Games or SUPW or
both
mysql > select name from student where (grade1='C' || grade2='C') or (grade1='C' &&
grade2='C') ;
Table :: TEACHER
No Name AgeDepartmen
tDateofjoin Salary Sex
1 Jugal 34 Computer 10/01/97 12000 M
2 Sharmila 31 History 24/03/98 20000 F
3 Sandeep 32 Maths 12/12/96 30000 M
4 Sangeeta 35 History 01/07/99 40000 F
5 Rakesh 42 Maths 05/09/97 25000 M
6 Shyam 50 History 27/06/98 30000 M
7 Shiv Om 44 Computer 25/02/97 21000 M
4
8 Shalakha 33 Maths 31/07/97 20000 F
1Q. To show all the information about the teacher of history department.
mysql > select * from teacher where department = ’History’ ;
2Q. To list the names of female teachers who are in Hindi department.
mysql > select name from teacher where sex = ‘F‘ and department = ‘Hindi’ ;
3Q. To list names of all teachers with their date of joining in ascending order.
mysql > select name, dateofjoin from teacher order by dateofjoin ;
Table :: CLUB
COACH_ID COACHNAME AGE SPORTS DATOFAPP PAY SEX
1 KUKREJA 35 KARATE 1996-03-
27
1000 M
2 RAVINA 34 KARATE 1998-01-
20
1200 F
3 KARAN 34 SQUASH 1998-02-
19
2000 M
4 TARUN 33 BASKETBALL 1998-01-
01
1500 M
5 ZUBIN 36 SWIMMING 1998-01-
12
750 M
6 KETAKI 36 SWIMMING 1998-02-
24
800 F
7 ANKITA 39 SQUASH 1998-02-
20
2200 F
8 ZAREEN 37 KARATE 1998-02-
22
1100 F
9 KUSH 41 SWIMMING 1998-01-
13
900 M
10 SHAILYA 37 BASKETBALL 1998-02-
19
1700 M5
1Q. To show all information about the swimming coaches in the club
mysql > select * from club where sports='SWIMMING' ;
2Q. To list names of all coaches with their date of appointment(DATOFAPP) in descending
order
mysql > select coachname,datofapp from club order by datofapp;
3Q. To display a report, showing coachname, pay, age and bonus(15% of pay) for all the
coaches
mysql > select coachname,pay,age,(pay *(15/100)) bonus from club ;
4Q. Give the output of the following SQL statements :
a) SELECT MOD(Age,5) FROM Club WHERE Sex = ’F’ ;
4 rows in set (0.01 sec)
b) SELECT LCASE(SPORTS) FROM Club ;
MOD(Age,5)
4
1
4
2
LCASE(SPORTS)
Karate
Karate
Squash
Basketball
Swimming
Swimming
Squash
Karate
Swimming
Basketball
6
10 rows in set (0.00 sec)
c) SELECT POWER(3,2) FROM Club WHERE Sports = ’KARATE’ ;
3 rows in set (0.03 sec)
d) SELECT SubStr(CoachName,1,2) FROM Club WHERE Datofapp > ‘1998-01-31’ ;
5 rows in set (0.02 sec)
Table :: MOVIE
POWER(3,2)
9
9
9
SubStr(CoachName,1,2)
KA
KE
AN
ZA
SH
7
1Q. Display a
list of all movies
with Price over 20
and sorted by price
mysql > select title
from movie
where price <
20.00 order by
price ;
2Q. Display all the movies sorted by qty in decreasing order
mysql > select title from movie order by qty desc ;
3Q. Display a report listing a movie number, current value and replacement value for each
movie in the above table. Calculate the replacement value for all movies as QTY * PRICE *
1.15
mysql > select no, rating, QTY * PRICE * 1.15 as replacement from movie ;
No Title Type Rating Stars Qty Price
1 Gone with the Wind Drama G Gable 4 39.9
5
2 Friday the 13th Horror R Jason 2 69.9
5
3 Top Gun Drama PG Cruise 7 49.9
5
4 Splash Comedy PG13 Hanks 3 29.9
5
5 Independence Day Drama R Turner 3 19.9
5
6 Risky Bussiness Comedy R Cruise 2 44.9
5
7 Cocoon Scifi PG Ameche 2 31.9
5
8 Crocodile Dundee Comedy PG13 Harris 2 69.9
5
9 101 Dalmatians Comedy G 3 59.9
5
10 Tootsie Comedy PG Hoffman 1 29.9
5
8
Table :: STUDENT1
1Q. Select all the
Nonmedical stream students from student1
mysql > select Name from student1 where Stream = ‘Nonmedical’ ;
2Q. List the names of the students who are in class 12 sorted by stipend.
mysql > select Name from student1 where Class = ‘12%’ order by stipend ;
3Q. List all students sorted by AvgMarks in descending order
mysql > select Name from student1 order by AvgMark desc ;
4Q. Display a report, listing Name, Stipend, Stream and amount of stipend received in a year
assuming that the stipend is paid every month
mysql > select Name, Stipend, Stream, (Stipend * 12) Amount_of_Stipend from student1;
No
.
Name Stipend Stream AvgMark Grade Class
1 Karan 400.00 Medical 78.5 B 12B
2 Divakar 450.00 Commerce 89.2 A 11C
3 Divya 300.00 Commerce 68.6 C 12C
4 Arun 350.00 Humanities 73.1 B 12C
5 Sabina 500.00 Nonmedical 90.6 A 11A
6 John 400.00 Medical 75.4 B 12B
7 Robert 250.00 Humanities 64.4 C 11A
8 Rubina 450.00 Nonmedical 88.5 A 12A
9 Vikas 500.00 Nonmedical 92.0 A 12A
10 Mohan 300.00 Commerce 67.5 C 12C
9
5Q. Give the output of the following SQL statements :
a) SELECT CONCAT(Name, Stream) FROM student1 WHERE class = ‘12A’ ;
2 rows in set (0.01 sec)
b) SELECT ROUND(AvgMark) FROM student1 WHERE Grade =’B’ ;
3 rows in set (0.01 sec)
c) SELECT TRUNCATE(AvgMark) FROM student1 WHERE AvgMark < 75 ;
4 rows in set (0.02 sec)
d) SELECT RIGHT(Stream, 2) FROM student1 ;
CONCAT(Name, Stream)
Rubina Nonmedical
Vikas Nonmedical
ROUND(AvgMark)
79
73
75
TRUNCATE(AvgMark)
68
73
64
67
RIGHT(Stream, 2)
Al
Ce
Ce
Es
Al
Al
Es
Al
Al
Ce
10
10 rows in set (0.02 sec)
Table :: LIBRARY
1Q. Select all the
PROG type published by BPB from Library
mysql > select * from library where (type=’PROG’ && pub=’BPB’);
2Q. Display a list of all books with Price more then 130 and sorted by QTY.
mysql > select title from library where price > 130 order by qty ;
3Q. Display all the books sorted by Price in ascending order.
mysql > select title from library order by price ;
4Q. Give the output of the following SQL statements :
a) SELECT UPPER(Title) FROM Library WHERE Price < 150 ;
No
.
Title Author Type Pub Qty Price
1 Data Structure Lipschutz DS McGraw 4 217
2 Computer Studies French FND Galgotia 2 75
3 Advanced Pascal Schildt PROG McGraw 4 350
4 Dbase dummies Palmer DBMS PustakM 5 130
5 Mastering C++ Gurewich PROG BPB 3 295
6 Guide Network Freed NET ZPress 3 200
7 Mastering Foxpro Segial DBMS BPB 2 135
8 DOS guide Norton OS PHI 3 175
9 Basic for beginners Morton PROG BPB 3 40
10 Mastering Window Cowart OS BPB 1 225
11
4 rows in set (0.02 sec)
b) SELECT CONCAT(Author, Type) FROM Library WHERE Qty < 3 ;
3 rows in set (0.02 sec)
c) SELECT MOD(Qty,4) FROM Library ;
10 rows in set (0.03 sec)
UPPER(Title)
COMPUTER STUDIES
DBASE DUMMIES
MASTERING FOXPRO
BASIC FOR BEGINNERS
CONCAT(Author, Type)
French FND
Segial DBMS
Cowart OS
MOD(Qty,4)
0
2
0
1
3
3
2
3
3
1
12
Table :: GRADUATE
1Q. List the names of
those students who have obtained Rank 1 sorted by NAME
mysql > select name from graduate where rank=1 order by name ;
2Q. Display a report, listing NAME, STIPEND, SUBJECT and amount of stipend received in a year
assuming that the stipend is paid every month
mysql > select name, stipend, subject, (stipend * 12) Amount_of_Stipend from graduate ;
No
.
Name Stipend Subject Average Rank
1 KARAN 400 PHYSICS 68 1
2 DIVAKAR 450 COMPUTER SC 68 1
3 DIVYA 300 CHEMISTRY 62 2
4 ARUN 350 PHYSICS 63 1
5 SABINA 500 MATHEMATICS 70 1
6 JOHN 400 CHEMISTRY 55 2
7 ROBERT 250 PHYSICS 64 1
8 RUBINA 450 MATHEMATICS 68 1
9 VIKAS 500 COMPUTER SC 62 1
10 MOHAN 300 MATHEMATICS 57 2
13
1Q What will be the output of the following code :
a) select concat ( concat ( ‘Inform’, ‘atics’ ) , ‘Practices’ ) ;
=> InformaticsPractices
b) select lcase (‘INFORMATICS PRACTICES CLASS 11TH’ ) ;
=> Informatics Practices class 11th
c) select ucase (‘Computer studies’) ;
=> COMPUTER STUDIES
d) select concat ( lower ( ‘Class’ ) , upper ( ‘xii’ ) ) ;
=> class XII
2Q. If str = “INFORMATICS PRACTICES “ and str1 = “FOR CLASS XI”, write commands to print
the output as ‘informatics practices for class xi’
mysql > select lower ( concate ( str, str1) ) ;
3Q. Write a command to display the system date.
mysql > select sysdate ( ) ;
4Q. Write command to display the name of current month.
mysql > select month ( currdate ( ) ) ;
14
5Q. Write SQL statement to display
Today, the date is <current date>
mysql > select concat('Today, the date is ',curdate());
6Q. Write command to print the day of the week of your Birthday in the year 1999.
mysql > select dayofweek ( "1999-01-22" ) ;
7Q. Write a command to display the current time
mysql > select now ( ) ;
8Q. Consider two fields B_date which stores the birthdate and J_date, which stores the joining
date of an employee. Write a command to find out and display the approximate age of any
employee as on today.
mysql > select year ( curdate ( ) ) – year ( b_date ) from employee ;
[assuming table name is employee ]
9Q. Show via query how many days remain until Christmas, Round fractional days using the
numeric function Round .
mysql > select round ( day ( '2010-12-25' ) – day ( curdate ( ) ) ) ;
10Q. Write a command to enlist the names of all tables created
mysql > show tables ;
11Q . Create table Customer as per Instance Chart
CUSTOMER
Column
Name
Cust_ID Cust_Name Cust_Address1 Cust_Address2 Pincode Cust_Phon
e
Datatype NUMBER VARCHAR VARCHAR VARCHAR NUMBER VARCHAR
Length 7 30 20 30 6 10
mysql > create table customer(Cust_ID int(7), Cust_Name varchar(30),
−> Cust_Address1 varchar(20), Cust_Address2 varchar(30)
−> Pincode int(6),Cust_Phone varchar(10)) ;
Query OK, 0 rows affected (0.05 sec)15
mysql > desc customer ;
Field Type Null Key Default Extra
Cust_ID int(2) YES NULL
Cust_Name varchar(20) YES NULL
Cust_Address1 varchar(20) YES NULL
Cust_Address2 varchar(30) YES NULL
Pincode int(6) YES NULL
Cust_Phone varchar(20) YES NULL
6 rows in set (0.00 sec)
12Q. Add one column Email of data type VARCHAR and size 30 to the Customer.
mysql > alter table customer add Email varchar(30) ;
13Q. Add one more column CustomerIncomeGroup of datatype VARCHAR(10)
mysql > alter table customer add CustomerIncomeGroup varchar(10) ;
14Q. Insert few records with revelant information, in the table.
mysql > insert into Customer values (1,’ABC’,’Add1’,’Add2’,500000,’9849298492’) ;
Query OK, 1 rows affected (0.03 sec)
mysql > insert into Customer values (2,’PQR’,’Add1’,’Add2’,500101,’9492194921’) ;
Query OK, 1 rows affected (0.03 sec)
mysql > insert into Customer values (3,’XYZ’,’Add1’,’Add2’,500040,’9989499894’) ;
Query OK, 1 rows affected (0.03 sec)
15Q. Drop the column CustomerIncomeGroup from table Customer
mysql > alter table Customer drop CustomerIncomeGroup ;
Query OK, 3 rows affected (0.17 sec)
Records : 3 Duplicates : 0 Warnings : 0
16Q. Create table Department as per Instance Chart
16
DEPARTMENT
Column Name DeptID DeptName
Key Type Primary
Nulls/Unique NOT NULL
Datatype NUMBER VARCHAR
Length 6 20
mysql > create table department(DeptID int(2) primary key, DeptName varchar(20) not null) ;
Query OK, 0 rows affected (0.14 sec)
mysql > desc department;
Field Type Null Key Default Extra
DeptID int(2) NO PRI NULL
DeptName varchar(20) NO NULL
2 rows in set (0.00 sec)
Q17. Create table Employee as per Instance Chart
EMPLOYEE
Column Name EmpID EmpName EmpAddress EmpPhone EmpSal DeptID
Key Type Primary Foreign
Nulls/Unique NOT NULL
Fk Table Departmen
t
Fk Column DeptID
Datatype NUMBER VARCHAR VARCHAR VARCHAR NUMBER NUMBER
Length 6 20 30 10 9,2 2
mysql > create table employee(EmpID int(6), EmpName varchar(10) not null,
−> EmpAddress varchar(30),EmpPhone varchar(10),
−> EmpSal float(9,2), DeptID int(2)
−> primary key(EmpId),
17
−> foreign key(DeptID) references department(DeptID)) ;
Query OK, 0 rows affected (0.06 sec)
mysql > desc employee;
Field Type Null Key Default Extra
EmpID int(6) NO PRI 0
EmpName varchar(10) NO NULL
EmpAddress varchar(30) YES NULL
EmpPhone varchar(10) YES NULL
EmpSal float(9,2) YES NULL
DeptID int(2) YES NULL NULL
6 rows in set (0.06 sec)
18