0% found this document useful (0 votes)
82 views4 pages

Date:20/05/2020 (Wed)

This document provides an assignment on SQL queries involving two tables: Employee and Department. It includes 20 multiple choice questions testing various SQL concepts like joins, aggregation functions, and scalar functions. It also provides sample queries to retrieve and manipulate data from the two tables based on various conditions. The assignment aims to assess the student's understanding of performing queries on multiple tables and different SQL clauses.

Uploaded by

adityatiw2111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views4 pages

Date:20/05/2020 (Wed)

This document provides an assignment on SQL queries involving two tables: Employee and Department. It includes 20 multiple choice questions testing various SQL concepts like joins, aggregation functions, and scalar functions. It also provides sample queries to retrieve and manipulate data from the two tables based on various conditions. The assignment aims to assess the student's understanding of performing queries on multiple tables and different SQL clauses.

Uploaded by

adityatiw2111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

SESSION 2020-21

Class XII
Computer Science(083)
(CH-13 More on SQL)
Topic :Queries Based on two tables
ASSIGNMENT 12
Name :___________ Date:20/05/2020(Wed)
Section A : MCQ Questions
1. Consider a relation/table EMP & DEPT and give the correct answer of following :
Relation EMP
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 1980-12-17 800.00 NULL 20
7499 ALLEN SALESMAN 7698 1981-02-20 1600.00 300.00 30
7521 WARD SALESMAN 7698 1981-02-22 1250.00 500.00 30
7566 JONES MANAGER 7839 1981-04-02 2975.00 NULL 20
7654 MARTIN SALESMAN 7698 1981-09-28 1250.00 1400.0 30
7698 BLAKE MANAGER 7839 1981-05-01 2850.00 NULL 30
7782 CLARK MANAGER 7839 1981-06-09 2450.00 NULL 10
7788 SCOTT ANALYST 7566 1982-12-09 3000.00 NULL 20
7839 KING PRESIDENT NULL 1981-11-17 5000.00 NULL 10
7844 TURNE SALESMAN 7698 1981-09-08 1500.00 0.00 30
7876 ADAMS CLERK 7788 1983-01-12 1100.00 NULL 20
7900 JAMES CLERK 7698 1981-12-03 950.00 NULL 30
7902 FORD ANALYST 7566 1981-12-03 3000.00 NULL 20
7934 MILLER CLERK 7782 1982-01-23 1300.00 NULL 10

Relation: DEPT
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON

1. SELECT AVG(SAL) FROM EMP WHERE JOB = ‘CLERK’;


(a) 1037.5 (b) 2073.21 (c) 1040 (d) 2074 (d:2074)
2. SELECT COUNT(*) FROM EMP WHERE DEPTNO = 10;
(a) 14 (b) 3 (c) 4 (d) 5 (b:3)
3. SELECT COUNT(DISTINCT JOB ) FROM EMP;
(a) 14 (b) 5 (c) 4 (d) 6 (b:5)
4. SELECT COUNT(ALL JOB ) FROM EMP;
(a) 14 (b) 5 (c) 4 (d) 6 (a:14)
5. SELECT MAX(SAL) FROM EMP WHERE JOB = ‘MANAGER’;
(a) 2975 (b) 5000 (c) 3000 (d) 2850 (a:2975)
6. SELECT MIN(HIREDATE) FROM EMP;
(a) 1980-12-17 (b) 1983-01-12 (c) 1982-12-09 (d) None (a:1980-12-17)
7. SELECT MAX(HIREDATE) FROM EMP;
(a) 1980-12-17 (b) 1983-01-12 (c) 1982-12-09 (d) None (b:1983-01-12)
8. SELECT SUM(COMM) FROM EMP;
(a) Null (b) 0 (c) 2200 (d) 1400 (c:2200)
9. Which statement is used to display the total no. of employees in each department?
(a) SELECT COUNT(*) FROM EMP WHERE DEPTNO;
(b) SELECT COUNT(*) FROM EMP GROUP BY DEPTNO;
(c) SELECT COUNT(DEPTNO) FROM EMP GROUP BY DEPTNO;
(d) (b) & (c) both (d:both)
10. To display the jobs where the number of employees is less than 3.
(a) SELECT JOB, COUNT(*) FROM EMP WHERE COUNT(*) < 3;
(b) SELECT JOB, COUNT(*) FROM EMP WHERE COUNT(*) < 3 GROUP BY JOB; (b)
(c) SELECT JOB, COUNT(*) FROM EMP GROUP BY JOB WHERE COUNT(*) < 3;
(d) SELECT JOB, COUNT(*) FROM EMP GROUP BY JOB HAVING COUNT (*) < 3;
11. Which join is used for display all possible concatenations are formed of all rows of two or more
tables.
(a) Unrestricted join (b) Cartesian Join
(c) Equi Join (d) (a) & (b) both (d:both)
12. How many row are returned when we execute ‘SELECT * FROM EMP, DEPT’;
(a) 14 (b) 4 (c) 18 (d) 56 (a:4)
13. To display the name of employee & department name the MySQL statement used:
(a) SELECT ENAME, DNAME FROM EMP, DEPT;
(b) SELECT ENAME, DNAME FROM EMP, DEPT WHERE DEPTNO=DEPTNO; (b)
(c) SELECT ENAME, DNAME FROM EMP, DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO;
(d) None of the above
14. The join where columns are compared for equality is called ……………… (a)
(a) Equi Join (b) Natural Join (c) Cross Join (d) Right Join
15. The join in which only one identical column exists is called ……… (b)
(a) Equi Join (b) Natural Join (c) Cross Join (d) Right Join
16. Which statement represent Cartesian join? (a)
(a) SELECT * FROM EMP, DEPT; (b) SELECT * FROM EMP JOIN DEPT;
(c) SELECT * FROM EMP CROSS JOIN DEPT; (d) All of the above
17. Using sub-clause with JOIN causes a ……………… join whereas on sub-clause with JOIN
produces ………… join. (a)
(a) Natural &Equi (b) Equi& Natural (c) Cross &Equi (d) Natural & Cross.
18. Using …………. all rows from the first table will be returned whether there are matches in the
second table or not.
(a) LEFT JOIN (b) RIGHT JOIN (c) EQUI JOIN (d) CROSS JOIN

19. Using …………. all rows from the second table will be returned whether there are matches in the
first table or not. (b)
(a) LEFT JOIN (b) RIGHT JOIN (c) EQUI JOIN (d) CROSS JOIN
20. To display the name of employees who are getting more salary than the maximum salary of clerks.
(a) SELECT ENAME FROM EMP WHERE
SAL >(SELECT MAX(SAL) FROM EMP WHERE JOB=’CLERK’);
(b) SELECT ENAME , MAX(SAL) FROM EMP WHERE JOB=’CLERK’;
(c) SELECT ENAME FROM EMP WHERE SAL >MAX(SAL);
(d) NONE (a)
21. Scalar functions are also known as :
(a) Single row function (b) Multiple row functions
(c) Group functions (d) None (a)

Section B : Queries
1. Consider the following tables : Employee and Department:
Table: Employee
ECode LastName FirstName DepName
101 Sharma Amit Sales
102 Arora Shiv Personnel
103 Lakshmi KS Accounts
104 Rajlani Shivika Accounts
105 Thakral Satvik Sales
Write SQL statements(a-k) to do the following:
a. Display the last names and first names of all employees.
Ans : select lastname, firstname from employee;
b. Display the Department names of all employees, without duplicates.
Ans : select distint(depname ) from employee.
c. Display all the details of employees whose last name is having “L”.
Ans :select * from employee where lastname like “%l%” ;
d. Display all the details of employees whose last name is “Rajlani” or “Sharma”.
Ans : select * from employee where lastname in (“Rajlani” , “Sharma”) ;
e. Display the codes and first names of all the employees of “Accounts” department.
Ans : select ecode , firstname from employee where depname = “accounts” ;

Table: Department
DepCode DepName Budget ECode
D101 Sales 200000 101
D102 Personnel 150000 102
D104 Accounts 300000 103
D103 Sales 200000 104
f. Display ECode , Firstname , department name of departments with budget above
180000.
Ans : select ecode , firstname , department.depname from employee , department
Where employee.ecode=department.ecode and budget>180000 ;
g. Display all the details of employees whose Last name begins with “S” and belongs to
Sales Department.
Ans : select employee. ecode , lastname , employee.depname from employee ,
department Where employee.ecode=department.ecode and lastname like “s%” and
depname=”sales” ;

h. Display department details ( from Department table) in descending order of Budget


Amount.
i. Change the Department name “Sales” to “Marketing” everywhere in the table
“Employee” and “Department”.
Ans : update employee , department
Set depname=”marketing where employee.ecode=department.ecode and
depname=”sales” ;

j. Add a new row with appropriate data values for ECode 105 in Department table.
Ans : Insert into department
values(“D103” , : sales”,200000,105) ;

k. An employee Shivalik Rajlani has left his job . Do the needful by removing his details
from the tables.
l. Show the Cartesian product of both tables.
m. What will be the degree and cardinality of both tables now.

2. Consider the tables given below. Table workshop is created before the workshops are organized.
Table “WrapUp” is created after the workshops to summarize about the actual number of
participants who attended the workshops and the highest designation amongst all the participants
who attended the workshops. Consider the tables given below.
Table : Workshop
WorkshopId Title Num_Speakers Number_Invites
551 Time Management 3 50
552 App Development 1 40
553 Development & Planning 2 20
554 Marketing Strategies 2 25

Table : WrapUP
WorkshopId ActualAttendees HighestAttendee
551 39 Associate Director
552 32 CEO
553 18 Sr. Executive
554 20 Sales Manager
** ActualAttendees column stores : Actual number of Attendees.
**HighestAttendee column stores : highest designation amongst participants.
a) Name the Primary keys in both the tables.
Ans : workshop : workshopid
Wrapup : workshopid
b) What should be the data type of ‘ActualAttendees’ column and ‘HighestAttendee’
column ?
Ans: the data type of ‘ActualAttendees’ column is integer and ‘HighestAttendee’
column is varchar(20)
c) To display WorkshopId, Title, Number_Invites and Highest attendee for those
workshops in which number of invites were more than 20.
Ans : select WorkshopId, Title, Number_Invites , Highest attendee from workshop ,
wrapup where workshop.workshopid=wrapup.workshopid and number_invites>20 ;

You might also like