Short Answer Type Questions
Question 1:
Write queries for (i) to (iv) and find ouputs for SQL queries (v) to (viii), which are based on the tables.
Table : VEHICLE
Note:
- PERKS is Freight Charges per kilometer.
- Km is kilometers Travelled
- NOP is number of passangers travelled in vechicle.
- To display CNO, CNAME, TRAVELDATE from the table TRAVEL in descending order of CNO.
- To display the CNAME of all customers from the table TRAVEL who are travelling by vechicle with code Vo1 or Vo2
- To display the CNO and CNAME of those customers from the table TRAVEL who travelled between ‘2015-1231’ and ‘2015-05-01’.
- To display all the details from table TRAVEL for the customers, who have travel distacne more than 120 KM in ascending order of NOE
- SELECT COUNT (*), VCODE FROM TRAVEL GROUP BY VCODE HAVING COUNT (*) > 1;
- SELECT DISTINCT VCODE FROM TRAVEL :
- SELECT A.VCODE, CNAME, VEHICLETYPE FROM TRAVEL A, VEHICLE B WHERE A. VCODE = B. VCODE and KM < 90;
- SELECT CNAME, KM*PERKM FROM TRAVEL A, VEHICLE B WHERE A.VCODE = B.VCODE AND A. VCODE ‘V05’;
Answer:
Question 2:
Consider the following tables SCHOOL and ADMIN and answer this question :
Give the output the following SQL queries :
- Select Designation Count (*) From Admin Group By Designation Having Count (*) <2;
- SELECT max (EXPERIENCE) FROM SCHOOL;
- SELECT TEACHER FROM SCHOOL WHERE EXPERIENCE >12 ORDER BY TEACHER;
- SELECT COUNT (*), GENDER FROM ADMIN GROUP BY GENDER;
Answer:
Question 3:
Write SQL qureries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which are based on the tables TRANSPORT and TRIE
Note:
- PERKS is Freight Charages per kilometer
- TTYPE is Transport Vehicle Type
Note:
- NO is Driver Number
- KM is Kilometer travelled
- NOP is number of travellers travelled in vehicle
- TDATE is Trip Date
- To display NO, NAME, TDATE from the table TRIP in descending order of NO.
- To display the NAME of the drivers from the table TRIP who are traveling by transport vehicle with code 101 or 103.
- To display the NO and NAME of those drivers from the table TRIP who travelled between ‘2015-02-10’ and ‘2015-04-01’.
- To display all the details from table TRIP in which the distance travelled is more than 100 KM in ascending order of NOP
- SELECT COUNT (*), TCODE From TRIP
GROUP BY TCODE HAVNING COUnT (*) > 1; - SELECT DISTINCT TCODE from TRIP;
- SELECT A.TCODE, NAME, TTYPE
FROM TRIP A, TRANSPORT B
WHERE A. TCODE = B. TCODE AND KM < 90; - SELECT NAME, KM *PERKM
FROM TRIP A, TRANSPORT B
WHERE A. TCODE = B. TCODE AND A. TCODE = 105′;
Answer:
- SELECT NO, NAME, TDATE FROM TRIP ORDER BY NO;
- SELECT NAME FROM TRIP
WHERE TCODE = 101 OR TCODE = 103; - SELECT NO AND NAME FROM TRIP
WHERE ‘2015-02-10’ < TDATE < ‘2015-04-01’; - SELECT NO, NAME, TDATE, KM, TCODE FROM TRIP
WHERE KM >100 ORDER BY NOP; - TO DISPLAY THE MORE THAN ONE COUNT OF TCODE FROM THE TABLE TRIP
- TO DISPALY SEPERATE TCODE OF TABLE TRIP
- TO DISPAY THE NAME AND CODE OF THOSE TRANS PORTERS, WHO HAVE TRAVELLED MORE THAN 90 KMS.
- TO DISPLAY THE NAME AND EXPENDITARE OF A TRANSPORTER WHO HAVE TCODE AS 105.
Question 4:
Write SQL query to add a column total price with datatype numeric and size 10, 2 in a table product.
Answer:
ALTER TABLE PRODUCT ADD TOTAL PRICE NUMBER (10,2).
Question 5:
Sonal needs to display name of teachers, who have “0” as the third character in their name. She wrote the following query.
SELECT NAME FROM TEACHER WHERE NAME = “$$0?”;
But the query is’nt producing the result. Identify the problem.
Answer:
The wildcards are incorrect. The corrected query is SELECT NAME FROM TEACHER WHERE NAME LIKE ‘_ _0%’.
Question 6:
Deepika wants to remove all rows from the table BANK. But he needs to maintain the structure of the table. Which command is used to implement the same?
Answer:
DELETE FROM BANK.
Question 7:
While creating table ‘customer’, Rahul forgot to add column ‘price’. Which command is used to add new column in the table. Write the command to implement the same.
Answer:
ALTER TABLE CUSTOMER ADD PRICE NUMBER (10, 2).
Question 8:
What is the use of wildcard
Answer:
The wildcard operators are used with the LIKE operator to search a value similar to a specific pattern in a column. There are 2 wildcard operators.
% – represents 0,1 or many characters – – represents a single number or character
Question 9:
Differentiate between DELETE and DROP table commands ?
Answer:
DELETE command is used to remove infor¬mation from a particular row or rows. If used without condition, it will delete all row information but not the structure of the table. It is a DML command.
DROP table command is used to remove the entire structure of the table and information. It is a DDL command
Long Answer Type Questions
Question 1:
Write SQL commands for the queries (i) to (iv) and output for (v) & (viii) based on a table COMPANY and CUSTOMER.
- To display those company name which are having prize less than 30000.
- To display the name of the companies in reverse alphabetical order.
- To increase the prize by 1000 for those customer whose name starts with „S?
- To add one more column totalprice with decimal] 10,2) to the table customer
- SELECT COUNT(*) , CITY FROM COMPANY GROUP BY CITY;
- SELECT MIN(PRICE), MAX(PRICE) FROM CUSTOMER WHERE QTY>10;
- SELECT AVG(QTY) FROM CUSTOMER WHERE NAME LIKE “%r%;
- SELECT PRODUCTNAME,CITY, PRICE
FROM COMPANY, CUSTOMER WHERE
COMPANY. CID=CUSTOMER.CID AND
PRODUCTNAME=”MOBILE”;
Answer:
- SELECT NAME FROM COMPANY WHERE COMPANY.CID=CUSTOMER. CID AND
PRICE < 30000; - SELECT NAME FROM COMPANY ORDER BY NAME DESC;
- UPDATE CUSTOMER
SET PRICE = PRICE + 1000
WHERE NAME LIKE ‘S%’; - ALTER TABLE CUSTOMER
ADD TOTALPRICE DECIMAL(10,2); - 50000,70000
- 11
Question 2:
Consider the following tables SCHOOL and ADMIN and answer this question :
Write SQL statements for the following:
- To display TEACHERNAME, PERIODS of all teachers whose periods are more than 25.
- To display all the information from the table SCHOOL in descending order of experience.
- To display DESIGNATION without dupli¬cate entries from the table ADMIN.
- To display TEACHERNAME, CODE and corresponding DESIGNATION from tables SCHOOL and ADMIN of Male teachers.
Answer:
- SELECT TEACHERNAME, PERIODS
FROM SCHOOL WHERE PERIODS>25: - SELECT * FROM SCHOOL;
- SELECT DISTINCT DESIGNATION FROM ADMIN;
- SELECT TEACHERNAME.CODE
DESIGNATION FROM
SCHOOL.CODE = ADMIN.CODE
WHERE GENDER = MALE;
Question 3:
Write SQL commands for the queries (i) to (iv) and output for (v) to (viii) based on the tables Watches’ and Sale given below.
- TO DISPLAY ALL THE DETAILS OF THOSE WATCHES WHOSE NAME ENDS WITH ‘TIME’
- TO DISPLAY WATCH’S NAME AND PRICE OF THOSE WATCHES WHICH HAVE PRICE RANGE IN BE-TWEEN 5000-15000.
- TO DISPLAY TOTAL QUANTITY IN STORE OF UNISEX TYPE WATCHES.
- TO DISPLAY WATCH NAME AND THEIR QUANTITY SOLD IN FIRST QUARTER;
- SELECT MAX (PRICE), MIN(QTY_STORE) FROM WATCHES;
- SELECT QUARTER, SUM(QTY SOLD) FROM SALE GROUP BY QUARTER;
- SELECT WATCH_NAME, PRICE, TYPE FROM WATCHES W, SALE S WHERE W. WAT£H1D!=S.WATCHID; (viii) SELECT WATCH_NAME, QTYSTORE, SUM (QTY_SOLD), QTY_STORESUM (QTYSOLD) “STOCK” FROM WATCHES W, SALE S WHERE W. WATCHID = S.WATCHID GROUP BY S.WATCHID;
Answer:
- SELECT * FROM WATCHES WHERE WATCH_NAME LIKE ‘%TIME’
(Vi mark for SELECT query) (Vi mark for where clause) - SELECT WATCH_NAME, PRICE WATCH WHERE PRICE BETWEEN 5000 AND 15000;
(Vi mark for SELECT query) (Vz mark for where clause) - SELECT SUM (QTY STORE) FROM WATCHES WHERE TYPE LIKE ‘UNISEX’;
(Vz mark for SELECT query) (Vi mark for where clause) - SELECT WATCHNAME, QTY SOLD FROM WATCHES W,SALE S WHERE W. WATCHID = S. WATCHID
AND QUARTER = 1;
Question 4:
Answer the questions (a) and (b) on the basis of the following tables SHOP and ACCESSORIES.
(a) Write the SQL queries:
- To display Name and Price of all the Accessories in ascending order of their Price.
- To display Id and SName of all Shop located in Nehru Place.
- To display Minimum and Maximum Price of each Name of Accessories.
- To display Name, Price of all Accessories and their respective SName where they are available.
(b) Write the output of the following SQL
- SELECT DISTINCT NAME FROM ACCESSORIES WHERE PRICE> =5000;
- SELECT AREA, COUNT(*) FROM SHOPPE GROUP BY AREA;
- SELECT COUNT (DISTINCT AREA) FROM SHOPPE;
- SELECT NAME, PRICE*0.05 DISCOUNT FROM ACCESSORIES WHERE SNO IN (‘S02‘,S03‘);
Answer:
(a)
- SELECT Name, Price FROM ACCESSORIES ORDER BY Price Asc;
- SELECT ID SName FROM SHOP WHERE Area=”Nehru Place”;
- SELECT Name, max (Price); min(Price) FROM ACCESSORIES, Group By Name;
- SELECT Name,price, Sname FROM
ACCESSORIES, SHOP WHERE SHOE
ID=ACCESSORIES.ID;
(b)
Question 5:
Write SQL queries for:
- To display name, fee, gender, joinyear about the applicants, who have joined before 2010.
- To display names of applicants, who are playing fee more than 30000.
- To display names of all applicants in ascending order of their joinyear.
- To display the year and the total number of applicants joined in each YEAR from the table APPLICANTS.
- To display the C_ID (i.e., CourselD) and the number of applicants registered in the course from the APPLICANTS and table.
- To display the applicant’s name with their respective course’s name from the tables APPLICANTS and COURSES.
- Give the output of following SQL statements:
- SELECT Name, Joinyear FROM APPLICANTS
WHERE GENDER=’F’ and C_ID=’A02′; - SELECT MIN (Joinyear) FROM
APPLICANTS
WHERE Gender=’m’; - SELECT AVG (Fee) FROM APPLICANTS
WHERE C_ID=’A0T OR C_ID=’A05′; - SELECT SUM- (Fee), C_ID FROM C_ ID
GROUP BY C_ID
HAVING COUNT(*)=2;
- SELECT Name, Joinyear FROM APPLICANTS
Answer:
- SELECT NAME,FEE,GENDER,JOINYEAR
FROM APPLICANTS
WHERE J OINYE AR <2010 - SELECT NAME FROM APPLICANTS WHERE FEE >30000
- SELECT NAME FROM APPLICANTS ORDERBY JOINYEAR ASC
- SELECT YEAR, COUNT]*) FROM
APPLICANTS GROUP BY YEAR; - SELECT C_ID, COUNT]*) FROM
APPLICANTS, COURSES GROUP BY ID
WHERE APPLICANTS.C_ID=COURSES. C_ID - SELECT NAME,COURSE FROM
APPLICANTS, COURSES
WHERE APPLICANTS. C_ID=COURSES. C_ID- Avisha 2009
- 2009
- 67
- 55000 A01
Question 6:
Write SQL queries for (a) to (g) and write the output for the SQL queries mentioned shown in (hi) to (h4) parts on the basis of table ITEMS and TRADERS :
- To display the details of all the items in ascending order of item names (i.e., INAME).
- To display item name and price of all those items, whose price is in the range of 10000 and 22000 (both values inclusive).
- To display the number of items, which are traded by each trader. The expected output of this query should be:
- To display the price, item name and quantity (i.e., qty) of those items which have quantity more than 150.
- To display the names of those traders, who are either from DELHI or from MUMBAI.
- To display the names of the companies and the names of the items in descending order of company names.
- Obtain the outputs of the following SQL queries based on the data given in tables ITEMS and TRADERS above.
- SELECT MAX (PRICE), MIN (PRICE) FROM ITEMS;
- SELECT PRICE*QTY
FROM ITEMS WHERE CODE-1004; - SELECT DISTINCT TCODE FROM ITEMS;
- SELECT INAME, TNAME FROM ITEMS I, TRADERS T WHERE I.TCODE=T.TCODE AND QTY< 100;
Answer:
- SELECT INAME FROM ITEMS ORDER BY
INAME ASC; - SELECT INAME, PRICE FROM ITEMS WHERE PRICE => 10000 AND PRICE =< 22000; (c) SELECT TCODE, COUNT (CODE) FROM ITEMS GROUP BY TCODE;
- SELECT PRICE, INAME, QTY FROM ITEMS WHERE (QTY> 150);
- SELECT TNAME FROM TRADERS WHERE (CITY = “DELHI”) OR (CITY = “MUMBAI”)
- SELECT COMPANY, INAME FROM ITEMS
ORDER BY COMPANY DESC; - (hi) 38000
1200
(h2)1075000
(h3)T01
T02
TO3
(h4) LED SCREEN 40 DISP HOUSE INC CAR GPS SYSTEM ELECTRONICS SALES
Question 7:
Write SQL queries for (a) to (f) and write the outputs for the SQL queries mentioned shown in (gl) to (g4) parts on the basis of tables PRODUCTS and SUPPLIERS
- To display the details of all the products in ascending order of product names (i.e., PNAME).
- To display product name and price of all those products, whose price is in the range of 10000 and 15000 (both values inclusive).
- To display the number of products, which are supplied by each suplier. i.e., the expected output should be;
- S01 2
- S02 2
- S03 1
- To display the price, product name and quantity (i.e., qty) of those products which have quantity more thhn 100.
- To display the names of those suppliers, who are either from DELHI or from CHENNAI.
- To display the name of the companies and the name of the products in descending order of company names.
- Obtain the outputs of the following SQL queries based on the data given in tables PRODUCTS and SUPPLIERS above.
- SELECT DISTINCT SUPCODE FROM PRODUCTS;
- SELEC MAX (PRICE), MIN (PRICE) FROM PRODUCTS;
- SELECT PRICE*QTY
FROM PRODUCTS WHERE PID = 104; (g4) - SELECT PNAME, SNAME
FROM PRODUCTS P, SUPPLIERS S WHERE E SUPCODE = S. SUPCODE
AND QTY>100;
Answer:
- SELECT * FROM PRODUCTS ORDER BY PNAME ASC;
- SELECT PNAME, PRICE FROM PRODUCTS WHERE ((PRICE => 10000) AND (PRICE = < 15000));
- SELECT SUPCODE, COUNT (PID) FROM PRODUCTS GROUP BY SUPCODE;
- SELECT PRICE, PNAME, QTY FROM PRODUCTS WHERE (QTY > 100);
- SELECT SNAME FROM SUPPLIERS WHERE ((CITY = “DELHI”) OR (CITY = “CHENNAI”));
- SELECT COMPANY, PNAME FROM PRO-DUCTS ORDER BY COMPANY DESC; 4
- SOI1
(gl)s02
s03
(g2) 28000
1100
(g3) 550000
(g4) PNAME SNAME Vi
DIGITAL CAMERA 14 X GETALL INC
PENDRIVE16 GB GETALL INC
Question 8:
Consider the following tables CARDEN and CUSTOMER and answer (b) and (c) parts of this question:
- Give a suitable example of a table with sample data and illustrate Primary and Alternate Keys in it.
- Write SQL commands for the following statements:
- To display the names of all the silver coloured cars.
- To display names of car, make and capacity of cars in descending order of their sitting capacity.
- To display the highest charges at which a vehicle can be hired from CARDEN.
- To display the customer name and the corresponding name of the cars hired by them.
- Give the output of the following SQL queries:
- SELECT COUNT(DISTINCT Make) FROM CARDEN;
- SELECT MAX(Charges), MIN (Charges) FROM CARDEN;
- SELECT COUNTS), Make FROM CARDEN;
Answer:
- Primary Key of CARDEN = Ccode CARDEN
Alternate Key = CarName:
Primary key of Customer = Code
Alternate Key of Customer = Cname 2 - SELECT CarName From CARDEN
WHERE Color = “SILVER”; - SELECT CarName, Make, Capacity From
CARDEN ORDER BY Capacity DESC; - SELECT MAX(Charges) Frm CARDEN;
- ELECT Cname, CarName From
CARDEN, CUSTOMER WHERE
CARDEN. Ccode = CUSTOMER. Ccode; - (i) 4
(ii) MAX(Charges) MIN (Charges)
35 112
(iii) 5
(iv) SX4
C Class
Question 9:
Consider the following tables CABHUB and CUSTOMER and answer (b) and (c) parts of this question :
- Give a suitable example of a table with sample data and illustrate Primary and Candidate Keys in it.
- Write SQL commands for the following statements:
- To display the names of all the white coloured vehicles.
- To display name of vehicle name and capacity of vehicles in ascending order of their sitting capacity.
- To display the highest charges at which a vehicle can be hired from CABHUB.
- To display the customer name and the corresponding name of the vehicle hired by them.
- Give the output of the following SQL queries :
- SELECT COUNT(DISTINCT Make) FROM CABHUB;
- SELECT MAX(Charges), MIN(Charges)
- FROM CABHUB;
- SELECT COUNT (*) Make FROM CABHUB;
- SELECT Vehicle FROM CABHUB WHERE Capacity=4;
Answer:
- Primary key of CABHUB = Vcode alternate key of CABHUB = Vehicle Name. Primary key of Customer = Ccode Alternate Key of CUSTOMER = Cname.
- (i) SELECT VehicleName FROM CABHUB
WHERE Colour = “WHITE”; - SELECT VehicleName, capacity From CABHUB ORDER BY Capacity ASC;
- SELECT MAX(Charges) FROM CABHUB;
- SELECT Cname,VehicleName FROM CABHUB, CUSTOMER WHERE CUSTOMER. Vcode=CABHUB. Vcode;
- (i) 4
(ii) MAX(Charges) MIN (Charges)
35 12
(iii) 5
(iv) SX4
C Class
Question 10:
Consider the following tables EMPLOYEE and DEPARTMENT and answer (a) and (b) parts of this question.
- Write SQL commands for the following statements:
- To display all DepName along with the DepCde in descending order of DepCde.
- To display the average age of Employees in DepCde as 103.
- To display the name of DepHead of the Employee named “Sanjeev P”
- To display the details of all employees who has joined before 2007 from EMPLOYEE table.
- Give the output of the following SQL queries:
- SELECT COUNT (DISTINCT DepCde) FROM EMPLOYEE;
- SELECT MAX(JoinDate), MIN (JointDate) FROM EMPLOYEE;
- SELECT TName, DepHead FROM EMPLOYEE E, DEPARTMENT D
WHERE E.DepCde = D.DepCde; - SELECT COUNT (*) FROM EMPLOYEE WHERE Salary > 60000 AND Age > 30;
Answer:
(a)
- SELECT DEPNAME, DEPARTME-NT.
DepCde FROM EMPLOYEE, DEPART
MENT WHERE EMPLOYEE. DepCDE=
DEPARTMENT. DepCde Order by DepCde DESC; - Select AVG (Age) from EMPLOYEE WHERE DepCde=”103″;
- SELECT DeptHead FROM DEPART
MENT WHERE Employee. TName=
“Sanjeev P” AND EMPLOYEE. DepCde
= DEPARTMENT. DepCde; - SELECT * from EMPLOYEE WHERE
joinDate<’01-JAN-2007′;
Question 11:
Consider the following tables WORKER and PAYLEVEL and answer (a) and (b) parts of this question:
(a) Write SQL commands for the following statements:
- To display the name of all Workers in descending order of DOB.
- To display NAME and DESIGN of those Workers, whose PLEVEL is either P001 or
- To display the content of all the workers table, whose DOB is in between ’19-JAN- 1984′ and ’18-JAN-1987′.
- To add a new row with the following:
19, ‘DayaKishore’, ‘Operator’, ‘P003′, ’19- Sep-2008’, ‘ll-Jul-1984’
(b) Give the output of the following SQL queries :
- SELECT COUNT (PLEVEL), PLEVEL FROM WORKER GROUP BY PLEVEL;
- SELECT MAX(DOB), MIN(DOJ) FROM WORKER;
- SELECT Name,PAY FROM WORKER
W,PAYLEVEL P WHERE W.LEVEL=
P.PLEVEL AND W.ECODE<13; - SELECT PLEVEL, PAYLEVEL
WHERE PLEVEL=”POO3″;
Answer:
(a)
- SELECT NAME FROM WORKER
ORDER BY DOBDESC; - SELECT NAME, DESIGN FROM WORKER WHERE PLEVEL=”POOO1″ OR
PLEVEL=”POO2″; - SELECT * FROM WORKER WHERE
DOB BETWEEN ’19-JAN-1984 AND ’18-JAN-1987′; - INSERT INTO WORKER VALUES (19,”DayaKISHORE”, “oPERATOR”, “P0003”,’19-Sep-2008′,’11-Jul-1984′)’
(b)
Question 12:
Consider the following tables EMPLOYEE and SALGRADE and answer (b) and (c) parts of this question:
(a) What do you understand by Selection and Projection operations in relational algebra ?
(b) Write SQL commands for the following statements :
- To display the details of all EMPLOYEES in descending order of DOJ.
- To display NAME and DESIGN of those EMPLOYEES, whose SAL-GRADE is either S02 or S03.
- TO display the content Of all the EMPLOYEES table, whose DOJ is in between ’09-Feb-2006′ and ’08-Aug-2009′.
- To add a new row with the following:
109, ‘HarishRoy’, ‘HEAD-IT’, ‘SOX, ’09-
Sep-2007′, ’21-Apr-1983’
(c) Give the output of the following SQL queries :
- SELECT COUNT(SGRADE), SGRADE
FROM EMPLOYEE GROUP BY
SGRADE; - SELECT MIN(DOB), MAX(DOJ) FROM EMPLOYEE;
- SELECT NAME, SALARY FROM
EMPLOYEE E, SAL-GRADE S WHERE
E.SGRADE= S.SGRADE AND E.ECODE<103′; - SELECT SGRADE, SALARY +HRA FROM SALGRADE WHERE SGRADE =SGRADE=’S02;’
Answer:
Projection(ff): In relational algebra, a projection is a unary operafion. The result of such projecion is defined as the set obtained when the components Of the tuple R are restriceted to the set {a1……an}. It discards (or excludes) the other attributes.
Selection(): In relational algebra, a selection
is a unary operation written as (R) or (R) where:
- a and b are attribute names.
- p is a binary operation in the set.
- v is a value constant.
- R is a relation.
The selection (R) selects all those tuples in R for which 9 holds between the a and the b
(b)
- SELECT FROM EMPLOYEE ORDER BY DOJ DESC;
- SELECT NAME, DESIGN FROM EMPLOYEE WHERE SGRADE – “S02” OR SGRADE = “SO3;
- SELECT * FROM EMPLOYEE WHERE DOJ BETWEEN ’09-FEB-2006′ AND ’08- AUG -200%
- INSERT INTO EMPLOYEE VALUES(109, “HARSH RAY”, “HEAD-IT.S02”, ’09-SEP-
2007′, ’21-APR-1983′);
Question 13:
Consider the following tables GAMES and PLAYER and answer (b) and (c) parts of this question :
(a)What do you understand by primary key and candidate keys ?
(b)Write SQL commands for the following statements:
- To display the name of all GAMES with their GCodes.
- To display details of those GAMES which are having PrizeMoney more than 7000.
- To display the content of the GAMES table in ascending order of Schedule Date.
- To display sum of PrizeMoney for each type of GAMES.
(c) Give the output of the following SQL queries:
- SELECT COUNT(DISTINCT Number) FROM GAMES;
- SELECT MAX(ScheduleDate), MIN(Sche- duleDate) FROM GAMES
- SELECT Name, GameName FROM GAMES G, PLAYER P
WHERE (G.Gcode=PGcode AND G.Pri- zeMoney>10000); - SELECT DISTINCT Geode FROM PLAYER;
Answer:
(a) An attribute or set of attributes which are used to identify a tuple uniquely is known as a primary key. If a table has more than one such attributes which identify a tuple uniquely than all such attributes are known as candidate keys.
(b)
- SELECT GameName, GCode FROM GAMES;
- SELECT * FROM Games WHERE PrizeMoney >7000;
- SELECT * FROM Games ORDER BY ScheduleDate;
- SELECT SUM(Pnzemoney) FROM Games GROUPBY Type;
(c)
- 2
- 19-Mar-2004 12-Dec-2003
- Ravi Sahai Lawn Tennis
- 101 108 103
Question 14:
Consider the following tables ACTIVITY and COACH and answer (a) and (b) parts of this question :
(a) Write SQL commands for the following statements:
- To display the names of all activities with their Acodes in descending order.
- To display sum of PrizeMoney for the Activities played in each of the Stadium separately.
- To display the coach’s name and acodes in ascending order of Acode from the table Coach.
- To display the content of the Activity table whose schedule date earlier than 01-01-2004 in ascending order of Participants Num.
(b) Give the output of the following SQL queries:
- SELECT COUNT (DISTINCT Participants Num) FROM ACTIVITY;
- SELECT MAX (Schedule Date), Min (Schedule Date) FROM ACTIVITY;
- SELECT Name, Activity Name FROM ACTIVITY A, COACH C
WHERE A.Acode=C.Acode AND A.Parti- cipants Num=10; - SELECT DISTINCT Acode FROM COACH;
Answer:
(a)
- SELECT Acodes, ActivityName FROM ACTIVITY ORDER BY ACode DESC;
- SELECT SUM(PrizeMoney) FROM ACTIVITY GROUP BY Stadium;
- SELECT Name, Acode FROM COACH ORDER BY Acode;
- SELECT * FROM ACTIVITY WHERE SchduleDate < ’01-Jan-2004′ ORDER BY ParticipantsNum;
(b)
- 3
- 12-Dec-2003 19-Mar-2004
- Ravinder Discuss Throw
- 1001
1008
1003
Question 15:
Consider the following tables RESORT and OWNEDBY and answer (a) and (b) parts of this question:
(a)Write SQL commands for the following statements:
- To display the RCODE and PLACE of all ‘5 STAR’ resorts in the alphabetical order of the place from table RESORT.
- To display the maximum and minimum rent for each type of resort from table RESORT.
- To display the details of all resorts which are started after 31-DEC-05 from table RESORT.
- Display the OWNER of all ‘5 STAR’ resorts from tables RESORT and OWNEDBY.
(b)Give output for the following SQL queries:
- SELECT MIN(RENT) FROM RESORT Where PLACE = ‘KERALA’;
- SELECT TYPE, START DATE FROM RESORT Where TYPE ‘2 STAR’
ORDERBY STARTDATE, - SELECT PLACE, OWNER FROM
OWNEDBY Where PLACE LIKE “%A”; - SELECT RCODE, RENT FROM RESORT, OWNEDBY WHERE (RESORT PLACE= OWNEDBY. PLACE AND TYPE = ‘3 STAR’);
Answer:
(a)
- SELECT RCODE, PLACE FROM RESORT mere TYPE = “5 STAR” ORDER
BY PLACE; - SELECr MAX (RENT), MIN (RENT) FROM RESORT GROUP BY TYPE;
- SELECT FROM RESORT WHERE OSWAAL (BSE Question Bank. COMPUTER SCIENCE – PYTHON, STARTDATE > ’31-DEC-05′;
- SELECT OWNER FROM RESOR OWNEDBY B WHERE (A.TYPE START’ AND A.PLACE B.PLACE);
(b)
Question 16:
Consider the following tables STORE and SUPPLIERS and answer (a) and (b) parts of this question:
(a) Write SQL commands for the following statements:
- To display details of all the items in the STORE table in ascending order of LastBuy.
- To display ItemNo and Item name of those items from STORE table whose Rate is more than 15 Rupees.
- To display the details of those items whose supplier code (Scode) is 22 or Quantity in Store (Qty) is more than 110 from the table Store.
- To display minimum Rate of items for each supplier individually as per Scode from the table STORE.
(b) Give the output of the following SQL queries:
- SELECT COUNT(DISTINCT Scode) FROM STORE;
- SELECT Rate* Qty FROM STORE WHERE ItemNo=2004;
- SELECT Item, Sname FROM STORE S, Suppliers P
- WHERE S.Scode=PScode AND ItemNo=2006;
- SELECT MAX(LastBuy) FROM STORE;
Answer:
(a)
- SELECT * FROM STORE ORDER BY LastBuy ASC;
- SELECT ItemNo, Item FROM STORE WHERE Rate > 15;
- SELECT * FROM STORE WHERE (Scode = ’22’ OR Qty >’110′);
- SELECT Sname, MIN(Rate) FROM STORE, SUPPLIERS WHERE STORE. Scode = SUPPLIERS.Scode GROUP BY Sname;
(b)
- 3
- 880
- Item Sname
Gel Pen Classic Premium Stationers - 24-Feb-10
Question 17:
Consider the following tables STOCK and DEALERS and answer (a) and (b) parts of this question:
(a)Write SQL commands for the following statements:
- To display the details of all Items in the STOCK table in ascending order of StockDate.
- To display ItemNo and Item name of those items from STOCK table whose UnitPrice is more than Rupees 10.
- To display the details of those items whose dealer code (Dcode) is 102 or quantity in STOCK (Qty) is more than 100 from the table Stock.
- To display maximum UnitPrice of items for each dealer individually as per Dcode from the table STOCK.
(b)Give the output of the following SQL queries:
- SELECT COUNT(DISTINCT Dcode)
FROM STOCK; - SELECT Qty* UnitPrice FROM STOCK WHERE ItemNo=5006;
- SELECT Item, Dname FROM STOCK S, Dealers D WHERE S.Dcode=D.Dcode AND ItemNo = 5004;
- SELECT MIN (StockDate) FROM STOCK;
Answer:
(a)
- SELECT*FROM STOCK ORDER BY StockDate;
- SELECT Item No, Item FROM STOCK WHERE UnitPrice >10;
- SELECT *FROM DEALERS, STOCK
WHERE (DEALERS.Dcode=”102″OR STOCK.Qty >100 and DEALERS. DCODE = STOCK.DCODE); - SELECT MAX (Unitprice) FROM DEALERS, STOCK ORDER BY STOCK. Dcode WHERE DEALERS.Dcode = STOCK.Dcode;
(b)
- 3
- 4400
- Item Dname
Eraser Big Clear Deals - 01-Jan-09