Anjeev Singh Academy

Class 12 Computer Science Sumita Arora Exercise Solution of Ch 12 Simple Queries in SQL

Class 12 Computer Science Sumita Arora Exercise Solution

Ch 12 Simple Queries in SQL

Consider table Empl given in solved problems and answer the following questions.

Table: Empl

empnoEnameJobmgrHiredatesalcommdeptno
8369SMITHCLERK89021990-12-18800.00NULL20
8499ANYASALESMAN86981991-02-201600.00300.0030
8521SETHSALESMAN86981991-02-221250.00500.0030
8566MAHADEVANMANAGER88391991-04-022985.00NULL20
8654MOMINSALESMAN86981991-09-281250.001400.0030
8698BINAMANAGER88391991-05-012850.00NULL30
8882SHIAVNSHMANAGER88391991-06-092450.00NULL10
8888SCOTTANALYST85661992-12-093000.00NULL20
8839AMIRPRESIDENTNULL1991-11-185000.00NULL10
8844KULDEEPSALESMAN86981991-09-081500.000.0030
8886ANOOPCLERK88881993-01-121100.00NULL20
8900JATINCLERK86981991-12-03950.00NULL30
8902FAKIRANALYST85661991-12-033000.00NULL20
8934MITACLERK88821992-01-231300.00NULL10

Q1. Write a query to display the EName and Sal of employees whose salary is greater than or equal to 2200 from table Empl.

Ans: SELECT EName, Sal FROM Empl WHERE sal >= 2200;

Q2. Write a query to display details of employees who are not getting commission from table Empl.

Ans: SELECT * FROM EMPL WHREE COMM IS NULL;

Q3. Write a query to display employee name and salary of those employee who don’t have there salary in the range of 2500 to 4000.

Ans: SELECT ENAME, SAL FROM EMPL WHERE SAL NOT BETWEEN 2500 AND 4000;

Q4. Write a query to display the name, job title and salary of employee who do not have manager.

Ans: SELECT ENAME, JOB, SAL FROM EMPL WHERE MGR IS NULL;

Q5. Write a query to display the name of employee whose name contains ‘A’ as third alphabet.

Ans: SELECT ENAME FROM EMPL WHERE ENAME LIKE ‘_ _ A%’;

Q6. Write a query to display the name of employee whose name contains ‘T’ as the last alphabet.

Ans: SELECT ENAME FROM EMPL WHERE ENAME LIKE ‘%T’;

Q7. Write a query to display the name of employee whose name contains ‘M’ as first alphabet ‘L’ as third alphabet.

Ans: SELECT ENAME FROM EMPL WHERE ENAME LIKE ‘M_L%’;

Q8. Write a query on the customers table whose output will exclude all customers with a rating <= 100, unless they are located in Shimla.

Ans: SELECT * FROM CUSTOMERS WHERE RATING <=100 OR CITY = ‘SHIMLA’;

Q9. Write a query that selects all orders (Order table) except those with zeros or NULLs in the amt field.

Ans: SELECT * FROM ORDER WHERE AMT <> 0 OR AMT IS NOT NULL;

Q10. Write SQL commands for the following on the basis of given table STUDENT:

Table : STUDENT

StudentNoClassNameGAMEGrade1SUPWGrade2
10
11
12
13
14
15
7
8
7
7
9
10
Sameer
Sujit
Kamal
Veena
Archana
Arpit
Cricket
Tennis
Swimming
Tennis
Basket Ball
Cricket
B
A
B
C
A
A
Photography
Gardening
Photography
Cooking
Literature
Gardening
A
C
B
A
A
C
TABLE: STUDENT
  • (i) Display the names of the students who are getting a grade ‘C’ in either GAME or SUPW.
  • (ii) Display the different games offered in the school.
  • (iil) Display the SUPW taken up by the students, whose name starts with ‘A’.

Ans:

  • (i) SELECT NAME FROM STUDENT WHERE GRADE1 =’C’ OR GRADE2 = ‘C’;
  • (ii) SELECT DISTINCT GAME FROM STUDENT;
  • (iii) SELECT SUPW, NAME FROM STUDENT WHERE NAME LIKE ‘A%’;

Q11. Write SQL commands for the following on the basis of given table SPORTS :

Table : SPORTS

StudentNoClassNameGame1Grade1Game2Grade2
10
11
12
13
14
15
7
8
7
7
9
10
Sameer
Sujit
Kamal
Veena
Archana
Arpit
Cricket
Tennis
Swimming
Tennis
Basket Ball
Cricket
B
A
B
C
A
A
Swimming
Skating
Football
Tennis
Cricket
Atheletics
A
C
B
A
A
C
TABLE : SPORTS
  • (i) Display the names of the students who have grade ‘C’ in either Game1 or Game2 or both.
  • (ii) Display the names of the students who have same game for both Game1 and Game2.
  • (iii) Display the games taken up by the students, whose name starts with ‘A’.

Ans:

  • (i) SELECT NAME FROM SPORTS WHERE GRADE1 =’C’ OR GRADE2 = ‘C’;
  • (ii) SELECT NAME FROM STUDENT WHERE Game1 = Game2 ;
  • (iii) SELECT Game1, Game2 FROM STUDENT WHERE Name LIKE ‘A%’;

Question 12.
Write SQL commands for the following on the basis of the given table CLUB :

Table: CLUB

COACH_IDCOACHNAMEAGESPORTSDATOFAPPPAYSEX
1.KUKREJA35KARATE27/03/19961000M
2.RAVINA34KARATE20/01/19981200F
3.KARAN34SQUASH19/02/19982000M
4.TARUN33BASKETBALL01/01/19981500M
5.ZUBIN36SWIMMING12/01/1998750M
6.KETAKI36SWIMMING24/02/1998800F
7.ANKITA39SQUASH20/02/19982200F
8.ZAREEN37KARATE22/02/19981100F
9.KUSH41SWIMMING13/01/1998900M
10.SHAILYA37BASKETBALL19/02/19981700M
  • (a) To show all information about the swimming coaches in the club.
  • (b) To list names of all coaches with their date of appointment (DATOFAPP) in descending order.
  • (c) To display a report, showing coachname, pay, age and bonus (15% of pay) for all the coaches.

Ans:

  • (a) SELECT * FROM CLUB WHERE SPORTS = ‘SWIMMING’ ;
  • (b) SELECT COACHNAME, DATEOFAPP FROM CLUB ORDER BY DATEOFAPP DESC ;
  • (c) SELECT COACHNAME, PAY, AGE, PAY *0.15 AS “BONUS” FROM CLUB ;

Question 13.
Write SQL commands for the following on the basis of the given table STUDENT1 :

Table: STUDENT1

No.NameStipendStreamAvgMarkGradeClass
1Karan400.00Medical78.5B12B
2Divakar450.00Commerce89.2A11C
3Divya300.00Commerce68.6C12C
4Arun350.00Humanities73.1B12C
5Sabina500.00Nonmedical90.6A11A
6John400.00Medical75.4B12B
7Robert250.00Humanities64.4C11A
8Rubina450.00Nonmedical88.5A12A
9Vikas500.00Nonmedical92.0A12A
10Mohan300.00Commerce67.5C12C
  • (a) Select all the Nonmedical stream students from STUDENTI.
  • (b) List the names of those students who are in class 12 sorted by Stipend.
  • (c) List all students sorted by AvgMark in descending order.
  • (d) Display a report, listing Name, Stipend, Stream and Amount of stipend received in a year assuming that stipend is paid every month.

Answer:

  • (a) SELECT * FROM STUDENT1 WHERE STREAM = “NONMEDICAL” ;
  • (b) SELECT NAME FROM STUDENT1 WHERE CLASS LIKE ‘12%’ ORDER BY STIPEND
  • (c) SELECT * FROM STUDENT1 ORDER BY AVGMARK DESC;
  • (d) SELECT NAME, STIPEND, STREAM, STIPEND * 12 AS “STIPEND AMOUNT IN YEAR” FROM STUDENT1;

More questions are on the way. coming soon.



Sorry! You cannot copy content of this page. Please contact, in case you want this content.

Scroll to Top