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

Expression: (Hots

Uploaded by

Ananya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Expression: (Hots

Uploaded by

Ananya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

T6.

Give at least four


examples of numeric functions.
.Which function returns the
18. Write the
remainder of numeriC expression
function which returns the character string by converting cach character to lower case.
19. Which function
retums length of a string?
20. What is the result
of expression MOD(57, 2)?
21. Write the name of
function, which returnms specified number of character from a string ?
22. How will
you remove leading and trailing blanks from a character string?
23. What is the result of ROUND(123.5678, 2)?
24. How will you count number of characters in a character
25. How will you get computer date ?
expression ?
26. Write a command to PRINT first three characters
27.
of"Information
A numeric data field AMOUNT stored the valuc as 30309.98. Write a command in SQL to round off
amount:
(a) Upto 1 decimal places (b) to a whole number. [HOTS
28. A numeric data ficld CNT contains 35675.8765. Write a command to round off CNT to
() Whole number (b) Upto 3 decimal places
29. Write a SQL function to remove
leading and trailing spaces from a character expression P, where
P "ANAY#JAIN#####" (where # denotes a blank space).
30. Answer the following:
(a) What will be the output of
SELECTROUND(124.44)+MOD(1200.87,3);
(6) What will be the output of
SELECT MOD(30.500,5)+ROUND(100.50,1);
(c)Write the commands to display the name of passenger and address of all the passengers after
removing the leading and trailing blanks from tiie table PASSMAST.
(d)Write the command to convert the message "ABC INTERNATIONAL PUBLIC SCHOOL" to lower
case.
(e) Writea command to display the system date.
31. Consider a table
Loan_Account with the following data
Table: Loan_Accounts

AccNo Cust Name Loan Amount| Instalments Int_Rate Start


_Date Interest
1 R.K. Gupta 300000
12.00 2009-07-19
-

S.P. Sharma S00000 10.00 2008-03-22


K.P. Jain 300000 36 NULL 2007-03-08
M.P. Yadav 800000 60 10.00 2008-06-12
5 S.P. Sinha 200000 36 12.50 2010-01-03
6 P. Sharma
700000 60 12.50
2008-06-05
K.S. Dhall S00000 48 NULL 2008-03-05
Write MySQL commands for the tasks I to 41 and write the
output for the MySQL commands 42 to 46:
Create Table /Insert Into:
1. Create the table
2.
Loan_Accounts (Primary key: AccNo).
Display the structure of the table LOAN_ACCOUNT.
3. Insert tuples in it.

312 agethor wth" Informatics Practices -

XII
26 Display
Contai

Simple SELECT query questions: SELECT


4. Display the details of all the loans.
S. Display the AccNo,Cust_Name, and Loan_Amount of allthe loans. 21.

Conditional SELECT query using WHERE Clause


instalments.
6. Display the details of all the loans with less than 40
started before 01-04-2009.
7. Display the AccNo and Loan_Amount of all the loans

8. Display the Int_Rate of all the loans started after 01-04-2009.


SELECT query Using NULL:
of interest is NULL.
Display the details of all the loans whose
rate
9.
of interest is not NULL.
10. Display the details of all the loans whose rate
SELECTquery Using DISTINCT Clause: loan amount should appear
A
11. Display the amounts of various loans from the table Loan_Accounts.
only once. instaiment
number of instalments of various loans from the table Loan_Accounts.
An
12. Display the
should appear only once...
SELECT query using Logical Operators(NOT, AND, OR):
13. Display the details of all the loans started after 31-12-2008 for
which the number of instalments are
more than 36.
have number of instalments
Display the Cust_Name and Loan_Amount for all the loans which do
not
14.
36.
15. Display the Cust_Name and Loan_Amount for all the loans for which the loan amount is less than
500000 or int_rate is more than 12.
16. Display the details of all the loans which started in the year 2009.
17. Display the details of aH the loans whose Loan_Amount is in the range 400000 to 500000.
18. Display the details of all the loans whose rate of interest is in the range 11% to 12%.

SELECTquery using IN Operator:


19. Display the Cust_Name and Loan_Amount for all the loans for which the number of instalments are
24, 36, or 48. (Using IN operator).
SELECTquery using BETWEEN Operator:
20. Display the details of all the loans whose Loan_Amount is in the range 400000 to S00000. (Using
BETWEEN operator).
21. Display the details of all the loans whose rate of interest is in the range 11% to 12%. (Using
BETWEEN operator).
SELECT query using LIKE Operator :
22. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name ends

with 'Sharma'.
23. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name ends

with 'a'.
24. Display the AcNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name
contains 'a'.
25. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name does
not contain 'P'.

Review of MySQL 313


26 Display the AccNo, Cust_Name. and Loan_ Amount for all the loans for which the Cust Nam.
contains 'a' as the second last character. ame

SELECT query using ORDER BY clause:


271. Display the details of all the loans in the ascending order of their Loan_Amount.
28. Display the details of all the loans in the descending order of their Start_Date
29. Display the details of all the loans in the ascending order of their Loan_Amount and within
Loan Amount in the descending order of their Start_Date.
Using UPDATE, DELETE,ALTERTABLE:
30. Put the interest rate 11.50% for all the loans for which interest rate is NULL.
31. Increase the interest rate by 0.5% for all the loans for which the loan amount is more than 400000
32. For each loan replace Interest with (Loan_Amount"Int_RateInstalments)/12*10.
33. Delete the records of all the loans whose start date is before 2007.
34. Delete the records of all the loans of 'K.P. Jain'.
35. Add another column Category of type CHAR(1) in the Loan table.

SELECT query using aggregate functions


36. To find the highest loan amount whose interest rate 12.00.
37. To find customer name and minimum loan amount which started in year 2009
38. To find the average loan amount.
39. To find the total loan amount which stated in year 2009.
40. To count total number of customer which interest rate is NULL.
41. To count total number of customers whose loan started after 2008;
Find the Output ofthe following queries:
FROM
42. SELECT cust_name, LENGTH(Cust_Name), LCASE(Cust_Name), UCASE(Cust_Name)
Loan_Accounts WHERE Int_Rate< 11.00;
43. SELECT LEFT(Cust_Name, 3), Right(Cust_Name, 3),
SUBSTR(Cust_Name, 1, 3) FROM
Loan_Accounts WHERE Int_Rate> 10.00;
44. SELECT RIGHT(Cust_Name, 3), SUBSTR(Cust_Name, 5) FROM Loan_Accounts;
45. SELECT DAYNAME(Start_Date) FROM Loan_Accounts;
WHERE Int_Rate> 10;
46. SELECT ROUND(Int_Rate*110/100, 2) FROM Loan_Accounts
commands:
32. Write the output produced by the following SQL
1. SELECT POW(4, 3), POW(3, 4);
2. SELECT ROUND(543.5694,2), ROUND(543.5694), ROUND(543.5694, -1);
SELECT TRUNCATE(543.5694, 2), TRUNCATE(543.5694, -1);
4. SELECT LENGTH(Prof. M. L. Sharma');
'FULLNAME;
5. SELECT CONCAT('SHEIKH, 'HAROON) DAY(CURDATEO);
6. SELECTYEAR(CURDATE), MONTH(CURDATE),
7. SELECTDAYOFYEAR(CURDATE), DAYOFMONTH(CURDATE)DAYNAME(CURDATEO);

8. SELECT LEFT(Unicode', 3), RIGHT(Unicode', 4);


9. SELECT INSTR(UNICODE, Co'), INSTR(UNICODE, CD);
10. SELECT MID(Informatics, 3, 4), SUBSTR(Practices, 3)
33. Write SQL commands for (a) to (d) on the
basis of table HOSPITAL.
TABLE: HOSPITAL
Datcofadm Charges Sex
No. Name Age Department
M
Surgery 1998-01-21 300
LIArprit
XII
314 Tagether artk Informatics Practices
-
HOSPITAL Table Data:
PNo Name Dateofadm Charges Sex
Age Department
300 M
Arprit 62
Surgery 2008-01-12
Zarina 22 ENT 2007-12-12 250
M
Kareem 32 Orthopacdic 2008-02-19 200
4 M
Aun 12 Surgery 2008-01-11 300
Zubin 30 ENT 2008-01-12 250 M
6 Ketaki 16 ENT 2008-02-24 250
7 Ankita 29
8
Cardiology 2008-02-20 800
Zareen 45
9
Gynaecology 2008-02-22 300 F
Kush 19
10 Shilpa 2 3
Cardiology 2008-01-13 800 M
Nuclear Medicine 2008-01-20 | 400 F
1. Write the command to create
2
HOSPITAL table.
Write a command to describe the
3 structure of the above table.
To select all the information of patients of
4To list the names of female patients who arecardiology
in ENT
department.
department
SMo list names of all patients with their date of admission
6 To in ascending order.
display Patient's Name, Charges,
Age of only female
7. To count the
number of patients with patients.
Age< 30
8Display the department wise
9Display the department wise total charges.
total charges whose maximum
10. Add one more
column in the above table as Address of charges more than equal to 300.
11. Modify the
column Address as char(25). type char(20).
12
Change name of the column Address to
the
13. Drop the column Home_address.
14 SELECT Home_Address.
15. SELECT COUNT(DISTINCT Charges) FROM HOSPITAL;
16. SELECT
MIN(Age) FROM HOSPITALWHERE
Sex "F;
=

SUM( Charges) FROM HOSPITAL WHERE


17.
SELECT AVG(Charges) FROM HOSPITAL WHERE Department= "ENT;
46. Write the SQL commands for deete (a) to () and write the Dateofadm< *2008-02-12;
TABLE:STUDENT outpüts for (g) on the basis
of table STUDENT.
Na Name Age Department Dateofadm Fees Sex
Pankaj 24
Computer 1997-01-10- 120 M
Shalini 21 History 1998-03-24 200
Sanjay 2 Hindi 1996-12-12 300
Sudha M
25 History 1999-07-01 400
Rakesh 22 Hindi
6
1997-09-05 250 M
Shakeel 30
History 1998-06-27 300 M
Surya 34
Computer
Shikha
1997-02-25 210 M
23 Hindi 1997-07-311 200
318 ether aah
Informatics Practices -

XII
G (a) To show all information about the students of
History department.
(6) To list the names of female students who are in Hindi
department.
(c) To list names of all students with their dateofadmission in ascending order.
(d)The display Student's Name, Fees, age of male students only.
Se) To count the number ofstudentswith age>23 s e l r coud C 1* whune,5
)To insert a new row in the STUDENT table with the following data :
9, 'Zaheer, 36, 'Computer, '1997-03-12', 230, 'M
(8) Give the output of the following SQL statements :[Include the last inserted values in part (OI
) SELECT COUNT(DISTINCT department) FROM sTUDENT,
Gi) SELECT MAX(Age) FROM STUDENT WHERE Sex = "F';
(i) SELECT AVG(Fees) FROM STUDENT WHERE SEX = 'M
(iv) SELECT SUM(Fees) FROM STUDENT WHERE Dateofadm<"1998-01-01;
47. Vrite the SQL for (a) to () and write the output of the (g) on the basis of the tablTEACHER:
TABLE:TEACHER
No. Name Age Department Dateofjoin Salary Sex
Jugal 34 Computer 1997-01-10 12000 M
2 Shamila 31 History 1998-03-24 20000 F

Sandeep 32 Maths 1996-12-12 30000 M

Sangeeta. 35
History 1999-07-01 40000 F
Rakesh 2 Maths 1997-09-05 25000 M
Shyam: Historry 1998-06-27 30000 M
Shiv Om- 4
Computer 21000 M
1997-02-25
Shalakha 3 3 Maths 1997-07-31 20000
(a)To show all information about the teacher of History department.
(6) To list the name of female teachers who are in Maths department.
(c) To list names of all teachers along with their date of joining in ascending order.
(d) To display teacher's Name, Salary, age for male teacher only.
(e) To count the number of teachers with age>23.
)To insert a new row in the TEACHER table with the following data:

ENT.. 9, Raja',26, 'Computer, '1995-05-13', 23000,'M'.


(g)Give the output of the following SQL statement :[Include the last inserted values in part ()]
() SELECT COUNT(DISTINCT department) FROM TEACHER;
(in SELECT MAX(Age) FROM TEACHER WHERE SEX="F';
(ii) SELECT AVG(Salary) FROM TEACHER WHERE SEX 'M; =

(iv) SELECT SUM(Salary) FROM TEACHER WHERE DATEOFJON < '1996-07-12';


48. Write SQL commands
for (a) to (d) and write the outputs for (e) on the basis of tables CLUB and
COACHES:
TABLE:CLUB

COACH ID COACH NAME AGE SPORTS DATEOFAPP PAY SEX


KUKREJA 35 KARATE 2002-03-27 1000 M
2 RAVINA 34 KARATE 2004-01-20 1200 F

Review of MySQL 319


2000 M
2004-02-19

KARAN 34 SQUASH
BASKETBALL 2004-01-01 1500M
4 TARUN 33 SWIMMING
2004-01-12
750 M

36
ZUBIN 800
KETAKI 36 SWIMMING2004-02-24
2200
2004-02-20
SQUASH
ANKITA 2004-02-222 1100 F
ZAREEN 37 KARATE
900 M
KUSH 41 SWIMMING 2004-01-13
M
37 BASKETBALL | 2004-02-19 1700
10 SHALYA

(a) To show all information about the swimming coaches in the club. order.
their date of appointment (DATEOFAPP) in descending
6) To list namesa of all coaches with for all the coaches.
To display report, showing coach name, pay, age and bonus (15% of pay)
(d)To insert a new row in the CLUB table with thefollowing data :
11, RAJIV, 40, 'Hockey, 2000-05-27, 2006,
(e) Give the output of the following SQL statements :[Include the last inserted values in part ()]
() SELECTCOUNT(DISTINCTSPORTS) FROMCLUB;
(i) SELECT MIN(AGE) FROM CLUB WHERE SEX = "F';

(ii) SELECTAVG(PAY)FROM CLUB WHERE SPORTS="KARATE';


(iv) SELECT SUMPAY) FROM CLUB WHERE DATEOFAPP> 2004-01-31;
49. Write SQLcommands for (a) to (c) and write the outputs for (e) on the basis of table GRADUATE:
TABLE:GRADUATE
SNO NAME STIPEND SUBJECT AVERAGE DIVI
1 KARAN 400
PHYSICS 68
2 DIVAKAR 450
COMPUTERSC 68
3 DIVYA 300 CHEMISTRY 62
ARUN 350
PHYSICS 63
S SABINA S00 MATHEMATICS 70
JOHN 400 CHEMISTRY
7 ROBERT 250 PHYSICS 64
RUBINA 450
MATHEMATICS 68
VIKAS S00 COMPUTER SC 62
0 MOHAN. 300 MATHEMATICS 57 2
List the names of those students who have obtained
(6) Display the report, listing NAME, DIVI =
1 sorted by NAME.
STIPEND, SUBJECT
assuming that the STIPEND is paid every month. . and amount of
stipend received in a year
(c)To count the number of
(d) To insert students who are either PHYSICS or COMPUTER SC
a new row in the graduates.
11, 'KAJOL', 300, GRADUATE table:
(e) Give the 'COMPUTER SC, 75,1
output of the following SQL statement based on table
[Include the last inserted values in
part (d)
GRADUATE:

320 Tagether wth Informatics Practices -

XII
M () SELECT MIN(AVERAGE) FROM GRADUATE WHERE SUBJECT="PHYSICS;
M
() SELECT SUM(STIPEND) FROM GRADUATE WHERE DIVI =2;
(i) SELECTAVG(STIPEND) FROM GRADUATE WHEREAVERAGE>=65;
(iv) SELECT COUNT(DISTINCT SUBJECT) FROM GRADUATE;
50. Write SQL commands for (a) to (g) on the basis of the table SPORTS.
TABLE:SPORTS

StudentNo Class Name Gamel Gradel Game2 Grade2


10 7 Sameer Cricket Swimming8 A
Sujit Tennis
Skating C
12 Kamal Swimming B Football B
3 Veena Tennis C Tennis A
14 Archana Basketball A Cricket A
15 10 Arpit Cricket A Athletics C

(a) Display the names ofthe students who have grade 'C in either Gamel or Game2 or both.
(b) Display the number of students getting grade 'A' in Cricket.
()Display the names ofthe students who have same game for both Gamel and Game2.
(a) Display the games taken up by the students, whose name starts with A'.
(e) Add a new column named 'Marks.
) Assigna value 200 for Marks for all those who are getting grade 'B' or grade'A' in both Gamel and
Game2.
(g) Arrange the whole table in the alphabetical order of Name.
51. Giventhe following Lab relations: Write SQL commands for questions (a) to () and the output for ().
TABLE: Lab

No ItemName CostPerltem Quantity DateofPurchase Waranty Operational


1Computer 60000 9 2006-05-21
Printer 15000 3
2007-05-21
Scanner 18000
2008-08-29
Camera 21000 2006-06-13
Hub 8000 2009-04-13
UPS S000 2006-05-21
Plotter 25000 2010-01-11 2 2
()To select the ItemName purchased after2007-10-31.
(6) To list the ItemName, which are within the Warranty period till present date (ie. current date).
()To list the ItemName in ascending order of the date of purchase where quantity is more than 3.
()To display ItemName, CostFerltem, and Quantity whose Warranty is over.
)To count the number of items whose cost is more than 10000.
To insert a new record in the Lab table with the following data
8, VCR, 10000, 2, 2010-02-02, 1, 2.
(8) Give the output of the following SQL command :[Include the last inserted values in part (]
() SELECT MIN(DISTINCT Quantity) FROM LAB;

Review of MSQL 321


Quantity
=
2;
FROM LAB
WHERE
SELECT MIN(Waranty)
) FROM LAB WHERE
Quantity>2;
< 2009-01-01;
SELECT SUM(CostPerltem) DateofPurchase
n) FROM LAB WHERE
AVG(CostPerltem) to () and the output for (R)
SELECT Write SQL command for question (a)
relation.
ven the following family
TABLE:FAMILY
Income Occupation
No Name FemaleMembers MalcMembers
67000 Service
-

Mishra 3
I50000 Business
Gupta 4
Khan 3 48000 Mixed
Chaddha 125000 Business
120000 Mixed
Yadav 2

Joshi 2 114000 Service


Maurya 45000 Faming
Rao 2 10000 Service

()To select all the information of family whose occupation is service.


(6) To list the name of family where female members are more than 3.
(To list all names of family with income in ascending order.
T o dispBay family's name, maie members and
occupation of
() To count the number of families whose income is less than business
family.
10,000.
T o insert a new record in the Family tabie with the foliowing data
9, "D'souza", 2, 1, 15000, 'Service'
(g) Give the output of the
following SQL command : Include the last inserted values in part ()]
() SELECT MIN(DISTINCT Income) FROM
Family;
(i) SELECT MIN(FemaleMembers) FROM WHERE Family
Occupation= 'mixed';
(iii) SELECT SUM(Income) FROM Family WHERE
(v) SELECTAVG(Income) FROM Family; Occupation 'Service;
53. Write SQL commands for the
queries for the questions given from to and write the output of the
SQL commands given in part (g) based on a relation TRAN shown(a) ()
below:
Relation: TRAIN
No TrainNe Name Ciass SeatNo
1
Age FareperTicket
S0001 ANU
6 700
SO02 SAGAR AC-CHAR 1300
3 S0003 SAMIR AC-I 8 9000
4 SO004 GAURAV 23 600
SO005 KAPL 25 1700
6 S0005 ANKUR 6 20 S00
7 SO003 PRIYA AC-II
1200
(a) To display the Name and Seat No. where Class is
I.
(b) To display Train No. and Seat No. where the Fare
per Ticket is> 1300
322 agaeher adth nformatics Practices XII
with 'A' in ascending
order of Train NO
l o display list of passengers having Name starting
(To display the highest amount paid as Fare per Ticket.
of of cach train
(elo display the Train No. and the number passengers data.
table with the following
) l o insert a new passenger in the
3000
8, 'S0002, RAMANLAL', "T, 2, 66, inserted values in part )I
following:[Include the last
)Write the output ofthe
TRAIN where Class- "Il';
() Select MIN(Age) from from TRAIN; in part
TRAINNO) commands given
(i) Select cOUNT(Distinct the output of the SQL
to (/) and write
commands for the queries (a)
54./Write SQL. below:
relation SHOP shown
() based on a
Relation : SHOP
Arca Cust_Percent Rating City
Sale C Delhi
No Shop_nanme 68.6
West
S. M. Sons
250000
81.8
A Mumbai
South
S00000 Kolkata
Dharohar
79.8 B
300000 North Mumbai
Kriti Art B
88.0
380000 North A Delhi
Ripple East 92.0
Biswas Stores
456000 Kolkata
South 66.7
290000
Crystal
South.
which are in the 80
the names of all shops
cust_percent>
(a) To display Percentage of all the shops having Shop_Name.
n a m e and
Customer order of
(6) To display in ascending those
the shops with sale > 300000 in the table, for only
()To display list of all Area and Rating for each shop
with Shop_name, both 350000 and
400000).
() To display report
a
and 400000 (including
350000 SHOP.
sa>e is between each city in the
table
shops whose the number of shops in data:
the City and following
(e) To display with the
shop in the table SHOP
T o insert
details ofa new 'A', 'Ahmedabad'
550000, 'South, 90.8, values in part ()]
7, The Shop, following:[Include
the last inserted
(Write the output ofthe from SHOP;
SelectMin(Cust_percent)
() Rating 'A';
=

SHOP where
Select Sum(Sale) from
(i)
from SHOP where City= 'Delhi';
(ii) Select Avg(Sale) from SHOP; command given
Count(Distinct City) write the output of the SQL
( ) Select given from (a) to () and
ofthe queries
55. Write sQL commands
FLIGHT:
based on a relation
in part (g)
Relation : FLIGHT
Distance Scats Frequency
FromCity ToCity
No FlightNo 1500 210
Yoyo Town
TI412
Blue Island
900 170
Yoyo Town
A3242 Pikswka
1000 210
Pikswaka
T1434 Perimila 1200 120
C3120 Ketty Island Blue Island
500 120
Jaswaka Perimila
T1418
Archie Land 1000 170
C3120 Pikswaka
6
323
Review of MysOL
7A3232 Harappan Valley Kety Island 900 T210
1200 120
1432 Blue Island Harappan Valley
more than 4 times in a weeK.
o display the FlightNo of those tlights which havethose
frequency
which are starting from city Blue
0)lo display FlightNo, FromCity and ToCity of all flights
Islands or are having destination as Bluc Islands.
flights in which seating capacity
is more than
To display FlightNo and Scating Capacity of all those
140
(To display FlightNo, Frequency and distance ofal those tlights, which are covering disiance more
than 900 kilometers.
(eTo display FlightNo ofall those flights which are Weekly ights and having seating capacity less
than 180.
T o insert a new flight detail in the table FLIGHT with the following data:
9,T1618, Mumsui', 'Blue Island', 1200, 210, 4
Write the output of the following:
SelectCOUNT(") from FLIGHT;
( Select MAX(Distance) from FLIGHT,
() Select MIN(Frequency) from FLIGHT;
() SelectCOUNT(Distinct FromCity) from FLIGHT,
Wnte SQL commands for the queries given from (a) to () and write the output of the SQL commands
given in part (g) based on a relation LIBRARY shown below:
Relation: LIBRARY

Title Author Subject Publisher| Quantity| Price


Data Structure Lipschute DS McGraw 4 217.00
DOS Guide NORTRON OS PHI 3 175.00
Turboc C++ Robort Lafore Prog Galgotia 270.00
Dbase Dummies Palmer DBMS PustakM 130.00
Mastering Windows Cowart BPB 225.00
Computer Studies French FND Galgotia 75.00
COBOL Stem Prog JohnW 1000.00
Guide Network Freed NET Zpress 200.00
3
9 Basic for Beginners Norton Prog BPB |3 40.00
10 Advanced Pascal Schildt Prog McGraw4 350.00
(To display the title ofall books with Price between 100 and 30o.
To display Title and Authorof all the books having type Prog and publisher by BPB.
(c)To display list ofall the books with price more than 130 in ascending order of Qty.
(d)To display a report with Title, Misplacement Charges (1.25 of price) for each book in the table.
T o display the publishers and the number of books of each publisher in the table LIBRARY.
)To insert a new book in the table LIBRARY with thefollowing data
11, 'CompSc., "Reeta', 'C+*, Rachna Sagar, 1, 225
(g) Write the output of the following :[Include the last inserted values in part ()1
() Select Min(Price) from LIBRARY;

324 agaha o t Informatics Practices XI


(ii) Select Sum(Price*QUANTITY) from LIBRARY where QUANTITY>3;
(in Select Avg(Price) from LIBRARY where QUANTITY <4;
(iv) Sclect Count(Distinct Publisher) from LIBRARY,
on the basis of the
table SUPPLIER:
Nrite the SQL commands for (a) to () and write the output of the (g)
TABLE: SUPPLIERR
SNo PName SName Qty Price City
SI Brcad Britannia L50 8.00 Delhi
250 20.00 Mumbai
S2 Cake Britannia
170 45.00 Mumbai
$3 Coffee Nescafe
10.00 Delhi
SA Chocolatc Amul 380
Kissan 470 36.00 Jaipur
S S5 Sauce
whose quantity is between 170 and 370.
(a) Display data for all products
sorted by their quantity.
(6) Display data for all products
that have no supplie
(c) Find all the products whose name starts with 'C'.
entire product
Give Sname for that is< 200.
for all the products whose quantity
Te) To list Sname, Pname, Price in descending order of quantity from the SUPPLIER table.
T o display SNo, Pname; Sname, Qty commands:
SQL
ands Give the output ofthe following
from SUPPLIER where price <30;
() SelectAVG(Price)
where price > 30;
(i) Select MAX(Price )from Supplier
(ii) Seloct SUM(Price*Qty) from Supplierwhere Qty <200;
(iv) Select COUNT(DISTINCT city) FROM supplier; the basis of the table BANK:
() and write the output ofthe (g)
on
58. Write the SQL commands for (a) to
TABLE: BANK
Amount Dateofopen T_Transactions
CName Bname
Acc_no 1998-01-12 10
Karan Bank of Baroda 15000
State Bank 25000 1997-02-01 09
Puneet
Oriental Bank 17000. 1999-07-15
Anirban
Standard Charteredd 38000 1999-02-10
Yatin
47000 1998-02-06 5
State Bank
Sunny
UCO Bank 34000 1998-08-100 07
Jayant
Bank of Baroda S6000 1999-01-02 12
Nikhil
Oriental bank 22000 1999-04-04 08
Tarun

9 Jisha UCO Bank 34500 1998-01-05 11


between 8 and 11.
(a) Display data for all Customers whose transaction is
(6) Display data for all Customers sorted by their dateofopen.
(c)To count the number of çustomers with amount <30000.
()List the minimum and maximum amount from the BANK.
() To list Cname, Bname, Amount for all the clients whose amount is 20000.
)To display Acc_no, Cname, Bname, Total transaction in descending order of Amount.

Review of MysQL 325


commands
() Give the output ofthe following SQL
BANK where amount 23000;
Select AVG{Amount) from BANK where amount> 30000;
(n) Select MAX(Amount) from
(i) Select SUM(T_Transactions) from BANK;
BANK;
() Select CcOUNT(DISTINCT Bname) FROM the basis ofthe table VOTER
the SQL commands for (a) to () and write the output of the (g) on
9.Wnte
TABLE: vOTER
Address Phonc
VNo Vname Age
Rohini 27045249
Diwaker 2
25S67892
Rajiv Sarojini Nagar
Paschim Vihar 25580438
Smith 24

Arpit 9 Multan Nagar 25585643


Dev Nagar 27123462
Sunny 26

Sumit 23 Vikas Puri 25565127


-

Raiv 2 Rohini 27869845


Rohit 24 Rohini 27057845
Anand Pitam Pura 27026534
10 Vidhi 26 Bank Vihar 27036713

() Write a SQL statement to list VNo, Vname, Age for all the voters sorted on Vname.
(6) To list all those voters who are either residing in Rohini or whose age < 25.

() Display all the voterwith age>27.


(d) List different voters with unique age.
(e Count the number of voters where iress is 'Rohini'.
Insert a new voter in the VOTERtable. Fill the entire column with values.
(g)Give theoutputof following SQL commands:
Select SUM(Age) from VOTER;
() Select COUNT(DISTINCT age) from VOTER;
(in Select MAX(age) from VOTER where age <26;
(iv) Select MIN(age) from VOTER where address="Paschim Vihar';
60. Write the SQL commands for (a) tò (f) on the basis of the table DIRECTORY
TABLE:DIRECTORY

Na Fname Lname Phone Address

Arpit Kumar 27045634 Rohini


Ram Sharma 25563412 Vikas Puri

Vikas 27865467 Pitam Pura


Malhotra
Rohit Arora 22235434 Preet Vihar
Kaushik 25567845 Paschim Vihar
Kisan
Rahul Verrma 27057456 Rohini
Rakesh Gulati 27026519 Pitam Pura

Arora 27018723 Rohini


Parul

Informatics Practices XII


326 agethor u
-
(a) To select all the information from DIRECTORY of Rohini arca.
(6) Update the database set the phone no. as 27047645 where phone number is 27057456.
c)To create a view called Dir with the following fields Fname, Phone, Address.
()To display the data for Arpit, Rahul and Kisan.
()To delete the rows where the address is Rohini.
)To delete the table physically.
the basis of table :
61. Write SQL commands for (a) to () and write the output for (g) on
TABLE:MOV
Rating Stars Qty Price
No. Title Type
Drama G Gable 4 39.9
Gone with the wind 69.95
Friday the 13th Horror R Jason
PG Cruise 49.95
TopGun Drama
PGI3 Hanks 29.95
Splash Comedy
Turner 19.95
Drama R
Independence Day 44.95
Risky Business Comedy R Cruise 31.95
Ameche
Scifi PG
Cocoon 69.95
Crocodile Dundee Comedy PG13 Harris
59.95
101 Dalmatians Comedy G
Hoffman 29.95
Comedy RG
10 Tootsie

cassettes available in the library.


the movie
(a) Find the total value of
with price over 20 and sorted by price.
(6) Display a list of all movies in descending order.
()Display all the movies sorted by Qty current value and replacement value
for each movie in the
movie number,
(a) Display report listing
a a
for all movies as:
above table. Calculate the replacementvalue
QTY PRICE*1.15.
where rating is not 'G'.
(e) Count the number of movies column with values.
MOV table. Fill the entire
) Insert a new movie in the
command:
g Give the output following SQL
ofthe
SelectAVG(Price) from MOV where Price < 30;
)
from MOV where Price> 30;
(in Select MAX(Price)
frot MOV where QTY<4;
(iin Select SUM(Price *Qty) FROMMOV;
iv) Select COUNT(DISTINCT TYPE) basis table:
62. Write the SQL commands for () )
to on the of
TABLE: PRODUCT

Stock
No. e Na Price Supplier -

Intel 20
Motherboard
1000 TVSE 0
Keyboard
Mouse 500 Logitech 60
S0
4 Soundcard 600 Samsung8
Speaker 600 Samsung 1_25
Review of MysQL 327
Monitor 22
3000 Philips
7 CD-ROM 2800 Creative 32
10
Printer 7900 HP
Display data for the entire item sorted by theirname.
() Display the Name and Price from the table item in descending order of their
stock.
(Lis all Nameand Price with Price between 3000 and 7000.
(a) Write the command to set the price ficld of all products to 1200 corresponding to NAME = Keyboard,

(2 Write the SQL command to delete rows with stock between 20 to 40.
T o count the number of products with stock <5.
T o delete the column puice.
63. What is NULL value ? What is the result of an arithmtic operation containing NULL value?
64. Write SQL commands for (a) to (d) and write the outputs for (e)on the basis of table EMPLOYEE:
TABLE:EMPLOYEE
SNO NAME BASIC DEPARTMENT DATOFAPP AGE SEX
35 M
KARAN 8000 PERSONNEL 1997-03-27
2 DIVAKAR 9S00 COMPUTER 1998-01-20 34 M

DIVYA 7300 ACCOUNTS 1997-02-19 34


ARUN 8350 PERSONNEL | 1995-01-01 33 M

5 SABINA 9500 ACCOUNTS 1996-01-12 36


JOHN 7400 FINANCE 1997-02-24 36 M

ROBERT 8250 PERSONNEL1997-02-20 39 M


RUBINA 9450 MAINTENANCE 1998-022 37 F
VIKAS L 7S00 41 M
COMPUTER 1994-01-13
10 MOHAN 9300 MAINTENANCE 1998-02-19 37 M

(a)List the names ofthe employees who are more than 34 years old sorted by NAME.
(6) Display a report, listing NAME, BASIC, DEPARTMENT and annual salary. Annual salary equals
BASICx 12.
()To count the number of employees who are either working in PERSONNELor COMPUTER department
(d) To insert a new row in the EMPLOYEE table:
11, VIJAY, 9300, 'FINANCE, '1998-07-13, 35, M
G i v e the output of the following SQL statement based on table EMPLOYEE:
() Select SUM(BASIC) from EMPLOYEE where DEPARTMENT= "PERSONNEL;
Select AVG(BASIC) from EMPLOYEE where SEX F;
=

iin
(ii) Select MAX(BASIC) from EMPLOYEE where DATOFAPP> '1997-02-22;
(iv) Select COUNT(DISTINCT DEPARTMENT) from EMPLOYEE
for () on the basis of table
65. Write SQL commands for (a) to (e) and write the outputs
TABLE:FURNITURE

NO mEMNAME TYPE DATEOFSTOCK PRICE DISCOUNT


white White lotus Double Bed 2002-02-23 30000 25

Practices XII
328 gether arck nformatics
2002-01-20 7000 20
Pink feather Baby cot
9500 20
Dolphin Baby cot 2002-02-19
25000
Decent Office Table 2002-02-01
25000 25
Comfort zone Double Bed 2002-02-12
6500 15
2002-02-24
Donald Baby cot 18000 30
Royal Finish Office Table 2002-02-20
31000 30
2002-02-22
8
Royal tiger Sofa 9500 25
9 Econo sitting Sofa 2001-12-13
Eating Paradise Dining Table 2002-02-19 11500 |25
10
FURNITURE table.
the Baby cots from the
()To show all information about than 15000 from the FURNITURE
table.
ITEMNAME which are priced at more from
(6) To list the before 2002-02-01
in which DATEOFSTOCK is
To list ITEMNAME and TYPE ofthose items,
) order ofITEMNAME.
the FURNITURE table in descending the DIScOUNT percentage
(To display ITEMNAME and
DATEOFSTOCK
ofthose items, in which
table.
is more than 25 from FURNITURE FURNITURE table.
number of items, whose TYPE is 'Sofa' from
(e) To count the
Give the output offollowing SQL statement:
from FURNITURE;
Select cOUNT(distinct TYPE)
(i). SelectMAX(DISCOUNT) from FURNITURE;
FURNITURE where TYPE "Baby cot';
=

(ii) Select AVG(DISCOUNT) from


where DATEOFSTOCK< 2002-02-12';
FURNITURE
(iv) Select SUM(PRICE) from of table
write the outputs for (e) on the basis
6. Write SQL commands for (a) to (d) and
TABLE: Books
Publishers| Price
Type Quantity
Book_Id Book_Bame Author_ Name
C0001 |Fast Cook Lata Kapoor EPB 355 Cookery
First Publ. 650 Fiction 20
FO001 The Tears William Hopkins
Brain &Brooke EPB 350 Text 10
My First C++
TOOO1 C+Brainworks| A.W. Rossaine TDH 350 Text 15
TOO02
FOO02 Thunderbolts Anna Roberts First Publ. 750 Fiction

of books of First Publ. Publishers.


(a) To show Book name, Author name and Price
(6) To list the names from books of Text type.
()To display the names and price from books in ascending order of their price.
() To increase the price of all books of EPB Publishers by 50.
() Give the output of the following queries based on the above tables (updated value for part (d)
should not be considered):
() SELECT COUNT(*)FROM Books;
(in SELECTMAX(Price) FROM Books WHERE Quantity>=15;
(ii) SELECT Book_Name, Author_Name FROM Books WHERE Publishers EPB
(v) SELECTCOUNT (DISTINCT Publishers) FROM Books WHERE Price>= 400,

Review ofMysQL 329


write the outputs for (e) and ) on the basis
oftable
0wie SQL commands for (a) ta (d) and
TABLE: GARMENT
FCODE READYDATE
PRICE
GCODE DESCRIPTION
FO3 2008-12-19
10023 PENCIL SKRIT 1150
FOl 2008-01-12
I0001 FORMAL SHIRT 1250
FO2 2008-01-06
10012 INFORMAL SHIRT 1550
2007-04-07
10024 BABY TOP 750 FO3
10090 TULIPSKIRT 850 F02 2007-03-31
10019 EVENING GOWN 850 F03 2008-01-06
10009 NFORMAL PANT 1500 F02 2008-10-20
1350 FO1 2008-03-09
10007 FORMALPANT

10020 FROCK 850 F4 2007-09-09


FO3 2008-10-20
10089 SLACKS 750
GARMENT in descending order of GCODE.
(a) To display GCODE and DESCRIPTION of each
have READYDATE between 2007-12-08 and
(6) To display the details of all the GARMENTs, which
6-JUN-08 (inclusive of both dates).
made up of FABRICwith FCODEas
()To display the average PRICE ofall the GARMENTS, which are
F03.
()To display FABRIC wise highest and lowest price of GARMENTs from GARMENT table. (Display
FCODE ofeach GARMENT along with highest and lowest price).
(e) SELECT SUM(PRCE) FROM GARMENT WHERE FCODE= "FO1'
SELECT COUNTDISTINCTPRICE) FROMGARMENT,
68. Consider the following table DRESS. Write SQL commands for the statements () to (iv) and give
outputs for SQL queries (v) and (vi)
TABLE: DRESS

DCODE DESCRIPTION PRICE MCODE LAUNCHDATE|


10001 FORMALSHIRT 1250 M001 2008-01-12
10020 FROCK 750 M004 2007-09-09
10012 INFORMALSHIRT 1450 MO02 2008-06-06

10019 EVENING GOWN 850 MO03 2008-06-06


I0090 TULIPSKIRT 850 MO02 2007-03-31

O023 PENCIL SKIRT 1250 M003 2008-12-19


10089 SLACKS 850 MO03 2008-10-20
1450 M001 2008-03-09
10007 FORMALPANT
1009 INFORMAL PANT 1400 MO02 2008-10-20
I0024 BABY TOP 650 MO03 2007-04-07

(To display DCODE and DESCRIPTION of each dress in descending order of DOCDE.

330 apther a t Informatics Practices - XII


2007-12-05 and 20
o display the details of al the dresses which have LAUNCHDATE betiween
06-08 (inclusive of both dates).
which up of matcrial
made with MCODE as MO3.
a y the
s pol display average PRICE
materialwise highest all the
ofand dresses are
lowest price of dresses from DRESS table. (Display MCODE of

cach dress along with highest and lowcst price).


WHERE MCODE "M001'
SELECT SUM(PRICE) FROM DRESS
=

PRICE) FROM DRESS;


Consider the COUNT(DISTINCT
6. SELECT following table STORE. Write SQL commnands for the statements (i) to (iv) and give

outputs for SQL queries (v) to (vi)


TABLE: STORE
Scode Qty Rate LastBuy
ItemNo Item
23 60 6 2009-06-31
Sharpener Classic
2005
50 25 2010-02-01
2003 Ball Pen 0.25
Gel Pen Premium 1S0 12 2010-02-24
2002
21 250 20 2009-03-11
2006 Gel Pen Classic
220 6 2009-01-19
2001 Eraser Small
2 110 2009-12-02
2004 Eraser Big
180 18 2009-11-03
Ball Pen 0.5 21
2009
order of LastBuy.
the items in the Store table in ascending
() To display details of all table whose Rate is more than 15 Rupees.
items from Store
ii) To display ItemNo and Item name of those is 22 or Quantity in Store (Qty) is
whose Supplier code (Scode)
(ii) To display the details of those items
more than 110 from the table Store.
thetable Store.
each Supplier individually as per Scode from
(iv) To display Minimum Rate of items for
(v) SELECT COUNTDISTINCT Scode) FROM Store;
(vi) SELECT Min(Rate) FROM Store;
(vii) SELECTMAX(LastBuy) FROM Store; values ? [HOTS
70. If the value in the column is repeatable, how will you find out the unique

ANSWERSTO
TOaREVOUS EARS QUESIONSTI2Marksl
1. USELBRARY,
2. ( Mname
Hirav
Rajeev
(ti) Mname
Rajeev
Sheetal
3. Number of rows are 8 and number of columns are 3.
4. Alternate key. There may be two or more attributes or combinations of attributes that uniquely identify
an instance of an entity set. In such a case, we must decide which of the candidate keys will be used as
the primary key. The remaining candidate keys would be considered alternate keys.
Candidate key. A candidate key is a combination of attributes that can be uniquely used to identify a
database record without any extraneous data. Each table may have one or more candidate keys. One of
these candidate keys is selected as the table primary key.

Review ofMySQL 331

You might also like