CBSE Class 12 Informatics Practices
Question 63 of 79
Database Query using SQL — Question 21
Back to all questions 21
Question Consider the following tables WORKER and PAYLEVEL and answer the questions:
Table: WORKER
| ECODE | NAME | DESIG | PLEVEL | DOJ | DOB |
|---|---|---|---|---|---|
| 11 | Sachin Patel | Supervisor | P001 | 2004-09-13 | 1985-08-23 |
| 12 | Chander Nath | Operator | P003 | 2010-02-22 | 1987-07-12 |
| 13 | Fizza | Operator | P003 | 2009-06-14 | 1983-10-14 |
| 15 | Ameen Ahmed | Mechanic | P002 | 2006-08-21 | 1984-03-13 |
| 18 | Sanya | Clerk | P002 | 2005-12-19 | 1983-06-09 |
Table: PAYLEVEL
| PLEVEL | PAY | ALLOWANCE |
|---|---|---|
| P001 | 26000 | 12000 |
| P002 | 22000 | 10000 |
| P003 | 12000 | 6000 |
(a) To display details of all workers in descending order of DOB.
(b) To display the PLEVEL and number of workers in that PLEVEL.
(c) To display the PLEVEL and number of workers in that PLEVEL whose pay is greater than 15000.
(d) To display NAME and DESIG of those workers, whose PLEVEL is either P001 or P002.
(e) Give the output of the following SQL queries:
- SELECT COUNT(PLEVEL), PLEVEL FROM WORKER GROUP BY PLEVEL;
- SELECT MAX(DOB), MIN(DOJ) FROM WORKER;
(a)
SELECT *
FROM WORKER
ORDER BY DOB DESC;+-------+--------------+------------+--------+------------+------------+
| ECODE | NAME | DESIG | PLEVEL | DOJ | DOB |
+-------+--------------+------------+--------+------------+------------+
| 12 | CHANDER NATH | OPERATOR | P003 | 2010-02-22 | 1987-07-12 |
| 11 | SACHIN PATEL | SUPERVISOR | P001 | 2004-09-13 | 1985-08-23 |
| 15 | AMEEN AHMED | MECHANIC | P002 | 2006-08-21 | 1984-03-13 |
| 13 | FIZZA | OPERATOR | P003 | 2009-06-14 | 1983-10-14 |
| 18 | SANYA | CLERK | P002 | 2005-12-19 | 1983-06-09 |
+-------+--------------+------------+--------+------------+------------+
(b)
SELECT PLEVEL, COUNT(*)
FROM WORKER
GROUP BY PLEVEL;+--------+----------+
| PLEVEL | COUNT(*) |
+--------+----------+
| P001 | 1 |
| P003 | 2 |
| P002 | 2 |
+--------+----------+
(c)
SELECT PL.PLEVEL, COUNT(*)
FROM WORKER W, PAYLEVEL PL
WHERE W.PLEVEL = PL.PLEVEL AND PL.PAY > 15000
GROUP BY PL.PLEVEL;+--------+----------+
| PLEVEL | COUNT(*) |
+--------+----------+
| P001 | 1 |
| P002 | 2 |
+--------+----------+
(d)
SELECT NAME, DESIG
FROM WORKER
WHERE PLEVEL IN ('P001', 'P002');+--------------+------------+
| NAME | DESIG |
+--------------+------------+
| SACHIN PATEL | SUPERVISOR |
| AMEEN AHMED | MECHANIC |
| SANYA | CLERK |
+--------------+------------+
(e)
1. SELECT COUNT(PLEVEL), PLEVEL FROM WORKER GROUP BY PLEVEL;
+---------------+--------+
| COUNT(PLEVEL) | PLEVEL |
+---------------+--------+
| 1 | P001 |
| 2 | P003 |
| 2 | P002 |
+---------------+--------+
2. SELECT MAX(DOB), MIN(DOJ) FROM WORKER;
+------------+------------+
| MAX(DOB) | MIN(DOJ) |
+------------+------------+
| 1987-07-12 | 2004-09-13 |
+------------+------------+