Test Index

CBSE Class 12 Computer Science 2025 Paper Set 4 Get it on Google PlayDownload on the App Store

© examsnet.com
Question : 32 of 37
Marks: +1, -0
Suman has created a table named WORKER with a set of records to maintain the data of the construction sites, which consists of WID, WNAME, WAGE, HOURS, TYPE, and SITEID. After creating the table, she entered data in it, which is as follows :
WIDWNAMEWAGEHOURSTYPESITEID
W01Ahmed J1500200Unskilled103
W11Naveen S520100Skilled101
W02Jacob B78095Unskilled101
W15Nihal K560110SemiskilledNULL
W10Anju S1200130Skilled103
(a) Based on the data given above, answer the following questions :
(i) Write the SQL statement to display the names and wages of those workers whose wages are between 800 and 1500.
(ii) Write the SQL statement to display the record of workers whose SITEID is not known.
(iii) Write the SQL statement to display WNAME, WAGE and HOURS of all those workers whose TYPE is 'Skilled'.
(iv) Write the SQL statement to change the WAGE to 1200 of the workers where the TYPE is "Semiskilled".
OR
(b) Considering the above given table WORKER, write the output on execution of the following SQL commands :
(i) SELECT WNAME, WAGE*HOURS FROM WORKER WHERE SITEID = 103;
(ii) SELECT COUNT (DISTINCT TYPE) FROM WORKER;
(iii) SELECT MAX(WAGE), MIN(WAGE), TYPE FROM WORKER GROUP BY TYPE;
(iv) SELECT WNAME,SITEID FROM WORKER WHERE TYPE="Unskilled" ORDER BY HOURS;
Solution:  
(a)
(a)(i) BETWEEN includes both end values.
SELECT WNAME, WAGE FROM WORKER
WHERE WAGE BETWEEN 800 AND 1500;
(same as WHERE WAGE >= 800 AND WAGE <= 1500; result: Ahmed J 1500, Anju S 1200)
(a)(ii) An unknown value is stored as NULL, and NULL is tested with IS NULL (not = NULL).
SELECT * FROM WORKER
WHERE SITEID IS NULL;
(result: the record of W15, Nihal K)
(a)(iii)
SELECT WNAME, WAGE, HOURS FROM WORKER
WHERE TYPE = 'Skilled';
(result: Naveen S 520 100, Anju S 1200 130)
(a)(iv) UPDATE … SET changes existing rows; the WHERE clause limits the change to Semiskilled workers.
UPDATE WORKER SET WAGE = 1200
WHERE TYPE = 'Semiskilled';
OR (b)
(b)(i) Rows with SITEID 103 are W01 and W10: 1500×200=3000001500 \times 200 = 300000 and 1200×130=1560001200 \times 130 = 156000.
WNAMEWAGE*HOURS
Ahmed J300000
Anju S156000
(b)(ii) The distinct values of TYPE are Unskilled, Skilled and Semiskilled.
COUNT(DISTINCT TYPE)
3
(b)(iii) One row per TYPE: Unskilled wages 1500, 780; Skilled 520, 1200; Semiskilled 560.
MAX(WAGE)MIN(WAGE)TYPE
1500780Unskilled
1200520Skilled
560560Semiskilled
(The order of the groups may differ from one DBMS to another; the values in each row do not.)
(b)(iv) Unskilled workers are Ahmed J (200 hours) and Jacob B (95 hours); ORDER BY sorts in ascending order by default.
WNAMESITEID
Jacob B101
Ahmed J103
© examsnet.com
Advertisements
Go to Question: