Comprehension

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 : 

Question: 1

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'.

Show Hint

Use BETWEEN for range filtering, IS NULL for missing values, WHERE for conditions, and UPDATE to change data.
Always enclose string conditions in single quotes in SQL.
Updated On: Jan 14, 2026
Show Solution

Solution and Explanation

(i)
SELECT WNAME, WAGE FROM WORKER WHERE WAGE BETWEEN 800 AND 1500;
This SQL statement retrieves the worker's name and wage from the WORKER table for all records where the wage is between 800 and 1500, inclusive.
Based on the provided data, this would include: Ahmed J (1500) and Anju S (1200). Jacob B (780) is excluded.
Therefore, the output is: Ahmed J, Anju S.
(ii)
SELECT * FROM WORKER WHERE SITEID IS NULL;
The clause IS NULL is used to identify rows with missing values in the SITEID column.
Note that in SQL, = NULL is invalid; only IS NULL can be used.
From the data, only Nihal K (W15) has a SITEID that is NULL.
Consequently, only this record will be displayed.
(iii)
SELECT WNAME, WAGE, HOURS FROM WORKER WHERE TYPE = 'Skilled';
This command selects the worker's name, wage, and hours from the WORKER table, specifically for records where the TYPE is 'Skilled'.
According to the data:
Naveen S (W11) and Anju S (W10) are both classified as Skilled.
(iv)
UPDATE WORKER SET WAGE = 1200 WHERE TYPE = 'Semiskilled';
This statement modifies the WAGE column to 1200 for all entries where the TYPE is 'Semiskilled'.
In the table, only Nihal K (W15) meets this criterion.
Was this answer helpful?
0
Question: 2

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;

Show Hint

Use GROUP BY for aggregation per category,
ORDER BY to sort results, and DISTINCT to eliminate duplicates.
NULL values are ignored in most aggregate and DISTINCT operations.
Updated On: Jan 14, 2026
Show Solution

Solution and Explanation

(i)

WNAME         WAGE * HOURS
Ahmed J       1500 * 200 = 300000
Anju S        1200 * 130 = 156000
Calculates WAGE multiplied by HOURS for workers where SITEID is 103.

(ii)

There are 4 distinct values in TYPE: Unskilled, Skilled, Semiskilled, NULL.
Note: NULL is not included in distinct counts by default.
Distinct count excluding NULL: Unskilled, Skilled, Semiskilled = 3.
If NULL is treated as a stored value and included by the SQL engine, the count could be 4.
Assuming NULL is excluded: Answer is 3
If NULL is stored as a valid string: Answer is 4

(Use 3 for MySQL default behavior.)

(iii)

TYPE         MAX(WAGE)     MIN(WAGE)
Unskilled    1500          780
Skilled      1200          520
Semiskilled  560           560
Groups records by TYPE and finds the maximum and minimum WAGE for each group.

(iv)

WNAME      SITEID
Jacob B    101
Ahmed J    103
Filters rows where TYPE is "Unskilled" and sorts them by HOURS in ascending order.
Jacob B (95 hours) comes before Ahmed J (200 hours).
The final order is: Jacob B, Ahmed J.

Was this answer helpful?
0