KnowledgeBoat Logo

Informatics Practices

Consider the following table and answer the questions that follow:

Table: TEACHER

IDNameDepartmentHiredateCategoryGenderSalary
1Tanya NandaSocialStudies1994-03-17TGTF25000
2Saurabh SharmaArt1990-02-12PRTM20000
3Nandita AroraEnglish1980-05-16PGTF30000
4James JacobEnglish1989-10-16TGTM25000
5Jaspreet KaurHindi1990-08-01PRTF22000
6Disha SehgalMath1980-03-17PRTF21000
8SonaliMukherjeMath1980-11-17TGTF24500

Write the command/output for the following:

(a) To display all information about the teacher of PGT category.

(b) To list the names of female teachers of Hindi department.

(c) To list names, departments and date of hiring of all the teachers in ascending order of date of joining.

(d) To count the number of teachers in English Department.

(e) Display the department and hire date of all the female teachers whose salary is more than 25000.

(f) Display the list of teachers whose name starts with J.

(g) SELECT COUNT(*) FROM TEACHER WHERE Category = 'PGT';

(h) SELECT AVG(Salary) FROM TEACHER GROUP BY Gender;

SQL Queries

4 Likes

Answer

(a)

SELECT * 
FROM TEACHER
WHERE CATEGORY = 'PGT' ;
Output
+----+---------------+------------+------------+----------+--------+--------+
| ID | NAME          | DEPARTMENT | HIREDATE   | CATEGORY | GENDER | SALARY |
+----+---------------+------------+------------+----------+--------+--------+
|  3 | NANDITA ARORA | ENGLISH    | 1980-05-16 | PGT      | F      |  30000 |
+----+---------------+------------+------------+----------+--------+--------+

(b)

SELECT Name 
FROM TEACHER 
WHERE Department = 'Hindi' AND Gender = 'F';
Output
+---------------+
| Name          |
+---------------+
| JASPREET KAUR |
+---------------+

(c)

SELECT NAME, DEPARTMENT, HIREDATE 
FROM TEACHER
ORDER BY HIREDATE;
Output
+------------------+---------------+------------+
| NAME             | DEPARTMENT    | HIREDATE   |
+------------------+---------------+------------+
| DISHA SEHGAL     | MATH          | 1980-03-17 |
| NANDITA ARORA    | ENGLISH       | 1980-05-16 |
| SONALI MUKHERJEE | MATH          | 1980-11-17 |
| JAMES JACOB      | ENGLISH       | 1989-10-16 |
| SAURABH SHARMA   | ART           | 1990-02-12 |
| JASPREET KAUR    | HINDI         | 1990-08-01 |
| TANYA NANDA      | SOCIALSTUDIES | 1994-03-17 |
+------------------+---------------+------------+

(d)

SELECT COUNT(*) 
FROM TEACHER
WHERE DEPARTMENT = 'ENGLISH';
Output
+----------+
| COUNT(*) |
+----------+
|        2 |
+----------+

(e)

SELECT DEPARTMENT, HIREDATE 
FROM TEACHER
WHERE GENDER = 'F' AND SALARY > 25000;
Output
+------------+------------+
| DEPARTMENT | HIREDATE   |
+------------+------------+
| ENGLISH    | 1980-05-16 |
+------------+------------+

(f)

SELECT Name 
FROM TEACHER  
WHERE Name LIKE 'J%';
Output
+---------------+
| Name          |
+---------------+
| JAMES JACOB   |
| JASPREET KAUR |
+---------------+

(g)

Output
+----------+
| COUNT(*) |
+----------+
|        1 |
+----------+

(h)

Output
+-------------+
| AVG(Salary) |
+-------------+
|  24500.0000 |
|  22500.0000 |
+-------------+

Answered By

2 Likes


Related Questions