0% found this document useful (0 votes)
12 views

Mock SQL Quiz (Not For Grading)

Uploaded by

sarlu341
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)
12 views

Mock SQL Quiz (Not For Grading)

Uploaded by

sarlu341
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/ 13

07/08/2024, 10:44 Mock SQL Quiz (Not for grading)

Dashboard / My courses / GEN-DBMS-SQL / Topic 1 / Mock SQL Quiz (Not for grading)

Started on Tuesday, 6 August 2024, 9:17 PM


State Finished
Completed on Wednesday, 7 August 2024, 12:57 AM
Time taken 3 hours 40 mins
Grade 21.00 out of 24.00 (88%)

Question 1

Correct

Mark 1.00 out of 1.00

Show the last name of all employees who have male dependents order by last name.

+---------+
| lname |
+---------+
| Smith |
| Wallace |
| Wong |
+---------+
3 rows in set (0.00 sec)

Answer: select distinct lname from employee join dependent where employee.ssn=dependent.essn order by lname; 

The correct answer is: select distinct lname from employee,dependent where ssn=essn and dependent.sex='M' order by lname.

172.16.201.202/moodle/mod/quiz/review.php?attempt=14289&cmid=14758 1/13
07/08/2024, 10:44 Mock SQL Quiz (Not for grading)

Question 2
Correct

Mark 1.00 out of 1.00

Find the total number of project hours for the Research department. Sort result set by project number.

sample output:

+------------+-----+
| sum(hours) | pno |
+------------+-----+
| 52.50 | 1 |
| 37.50 | 2 |
| 50.00 | 3 |
+------------+-----+
3 rows in set (0.03 sec)

Answer: select sum(hours),pno from works_on where pno in (1,2,3) group by pno; 

The correct answer is: select sum(hours),pno from works_on where pno in (select pnumber from project where dnum=(select dnumber from
department where dname='Research')) group by pno order by pno.

Question 3

Not answered

Marked out of 1.00

Display the age of all employees ordered by increasing age.


Hint: Use function current_date() to get today's date and function year() to extract the YEAR component from a date
sample output:

+------+
| age |
+------+
| 50 |
| 53 |
| 54 |
| 57 |
| 60 |
| 67 |
| 81 |
| 85 |
+------+
8 rows in set (0.00 sec)

Answer: 

The correct answer is: select year(current_date)-year(bdate) as age from employee order by age asc.

172.16.201.202/moodle/mod/quiz/review.php?attempt=14289&cmid=14758 2/13
07/08/2024, 10:44 Mock SQL Quiz (Not for grading)

Question 4
Correct

Mark 1.00 out of 1.00

Select ssn of employees whose average project hours is at least 10 hours and sort the results by ssn.

sample output:
+-----------+------------+
| essn | sum(hours) |
+-----------+------------+
| 123456789 | 40.00 |
| 333445555 | 40.00 |
| 453453453 | 40.00 |
| 666884444 | 40.00 |
| 987654321 | 35.00 |
| 987987987 | 40.00 |
| 999887777 | 40.00 |
+-----------+------------+
7 rows in set (0.00 sec)

Answer: select essn,sum(hours) from works_on group by essn having sum(hours)>=10 order by essn; 

The correct answer is: select essn, sum(hours) from works_on group by essn having sum(hours) >= 10 order by essn;.

Question 5

Not answered

Marked out of 1.00

List of employees whose salary is greater than their department average

and sort the result by the fname.

sample output:
+----------+

| fname |

+----------+

| Franklin |
| Jennifer |

| Ramesh |

+----------+

3 rows in set (0.00 sec)

Answer: 

The correct answer is: select fname from employee e1 where salary > (select avg(salary) from employee e2 where e1.dno = e2.dno) order by
fname;.

172.16.201.202/moodle/mod/quiz/review.php?attempt=14289&cmid=14758 3/13
07/08/2024, 10:44 Mock SQL Quiz (Not for grading)

Question 6
Correct

Mark 1.00 out of 1.00

Select Employees fname with having letter 's' anywhere in their First name arrange results set by the first name.

sample output:
+--------+
| fname |
+--------+
| James |
| Ramesh |
+--------+
2 rows in set (0.00 sec)

Answer: select fname from employee where fname like '%s%' order by fname; 

The correct answer is: select fname from employee where fname like '%s%' order by fname.

Question 7

Correct

Mark 1.00 out of 1.00

Find employees fname, lname, salary having a salary of at least 25000 and arrange the resultset by the last name.
sample output :

+----------+---------+----------+
| fname | lname | salary |
+----------+---------+----------+
| James | Borg | 55000.00 |
| Joyce | English | 25000.00 |
| Ahmad | Jabbar | 25000.00 |
| Ramesh | Narayan | 38000.00 |
| John | Smith | 30000.00 |
| Jennifer | Wallace | 43000.00 |
| Franklin | Wong | 40000.00 |
| Alicia | Zelaya | 25000.00 |
+----------+---------+----------+
8 rows in set (0.00 sec)

Answer: select fname,lname,salary from employee where salary>=25000 order by lname; 

The correct answer is: select fname, lname, salary from employee where salary>=25000 order by lname.

172.16.201.202/moodle/mod/quiz/review.php?attempt=14289&cmid=14758 4/13
07/08/2024, 10:44 Mock SQL Quiz (Not for grading)

Question 8
Correct

Mark 1.00 out of 1.00

Find different unique project locations alphabetically.

sample output:

+-----------+

| plocation |
+-----------+

| Bellaire |

| Houston |

| Stafford |

| Sugarland |

+-----------+

Answer: select distinct Plocation from project order by Plocation; 

The correct answer is: select distinct plocation from project order by plocation;.

Question 9

Correct

Mark 1.00 out of 1.00

Find the male employees who were born after 1950, arrange the resultset based on salary.
sample output:

+----------+-------+---------+-----------+------------+--------------------------+------+----------+-----------+------+
| fname | minit | lname | ssn | bdate | address | sex | salary | super_ssn | dno |
+----------+-------+---------+-----------+------------+--------------------------+------+----------+-----------+------+
| Ahmad | V | Jabbar | 987987987 | 1969-01-09 | 980 Fondren, Houston, TX | M | 25000.00 | 987654321 | 4 |
| John | B | Smith | 123456789 | 1965-01-09 | 731 Fondren, Houston, TX | M | 30000.00 | 333445555 | 5 |
| Ramesh | K | Narayan | 666884444 | 1962-01-09 | 975 Fondren, Houston, TX | M | 38000.00 | 333445555 | 5 |
| Franklin | T | Wong | 333445555 | 1955-01-09 | 638 Fondren, Houston, TX | M | 40000.00 | 888665555 | 5 |
+----------+-------+---------+-----------+------------+--------------------------+------+----------+-----------+------+
4 rows in set (0.00 sec)

Answer: select * from employee where sex='M' and Bdate>='1950-01-01' order by salary; 

172.16.201.202/moodle/mod/quiz/review.php?attempt=14289&cmid=14758 5/13
07/08/2024, 10:44 Mock SQL Quiz (Not for grading)

Question 10
Correct

Mark 1.00 out of 1.00

Find employees fname, lname, bdate salary having no manager or having salaries less than 30000 arrange resultset by the youngest
employee to the oldest.

sample output:

+--------+---------+------------+----------+
| fname | lname | bdate | salary |
+--------+---------+------------+----------+
| Joyce | English | 1972-01-09 | 25000.00 |
| Ahmad | Jabbar | 1969-01-09 | 25000.00 |
| Alicia | Zelaya | 1968-01-09 | 25000.00 |
| James | Borg | 1937-01-09 | 55000.00 |
+--------+---------+------------+----------+
4 rows in set (0.00 sec)

Answer: select fname,lname,bdate,salary from employee where (salary<30000 or super_ssn is NULL) order by bdate desc; 

The correct answer is: select fname, lname, bdate, salary from employee where salary<30000 or super_ssn IS NULL order by bdate desc;.

Question 11

Correct

Mark 1.00 out of 1.00

Find all the female employees having salary within the range of 30000 and 50000 arrange result by department number. (without using
operators like <,>)

sample output:

+----------+-------+---------+-----------+------------+-------------------------+------+----------+-----------+------+
| fname | minit | lname | ssn | bdate | address | sex | salary | super_ssn | dno |
+----------+-------+---------+-----------+------------+-------------------------+------+----------+-----------+------+
| Jennifer | S | Wallace | 987654321 | 1941-01-09 | 21 Fondren, Houston, TX | F | 43000.00 | 888665555 | 4 |
+----------+-------+---------+-----------+------------+-------------------------+------+----------+-----------+------+
1 row in set (0.00 sec)

Answer: select * from employee where (sex='F' and salary between 30000 and 50000) order by dno; 

172.16.201.202/moodle/mod/quiz/review.php?attempt=14289&cmid=14758 6/13
07/08/2024, 10:44 Mock SQL Quiz (Not for grading)

Question 12
Correct

Mark 1.00 out of 1.00

Find employees fname not having any dependents arrange results by the first name.

sample output:

+--------+
| fname |
+--------+
| Ahmad |
| Alicia |
| James |
| Joyce |
| Ramesh |
+--------+
5 rows in set (0.00 sec)

Answer: select fname from employee where employee.ssn not in (select dependent.essn from dependent) order by fname

The correct answer is: select fname from employee where ssn NOT IN ( select distinct essn from dependent) order by fname;.

Question 13

Correct

Mark 1.00 out of 1.00

Find minimum salary under the Research department.

+-------------+

| min(salary) |
+-------------+

| 25000 |

+-------------+

1 row in set (0.13 sec)

Answer: select min(salary) from employee group by Dno having Dno='5'; 

The correct answer is: select min(salary) from employee where dno=(select dnumber from department where dname='Research').

172.16.201.202/moodle/mod/quiz/review.php?attempt=14289&cmid=14758 7/13
07/08/2024, 10:44 Mock SQL Quiz (Not for grading)

Question 14
Correct

Mark 1.00 out of 1.00

Display first name of all employees. Use 'First' as the column alias.Arrange result set by first name.

+----------+

| First |

+----------+
| Ahmad |

| Alicia |

| Franklin |

| James |

| Jennifer |

| John |

| Joyce |

| Ramesh |

+----------+

8 rows in set (0.00 sec)

Answer: select fname as 'First' from employee order by fname; 

The correct answer is: select fname 'First' from employee order by fname;.

Question 15

Correct

Mark 1.00 out of 1.00

Show the sum of salaries of all the male employees and all the female employees ordered by sex.
+------+-------------+

| sex | sum(salary) |

+------+-------------+

|F | 136000 |

|M | 150000 |

+------+-------------+

Answer: select sex,sum(salary) from employee group by sex order by sex; 

The correct answer is: select sex,sum(salary) from employee group by sex order by sex.

172.16.201.202/moodle/mod/quiz/review.php?attempt=14289&cmid=14758 8/13
07/08/2024, 10:44 Mock SQL Quiz (Not for grading)

Question 16
Correct

Mark 1.00 out of 1.00

Show the count of employees who belong to department 5.

+----------+

| count(*) |

+----------+

| 4|

+----------+

Answer: select count(*) from employee where dno='5'; 

Question 17

Not answered

Marked out of 1.00

Show the ssn and total number of hours worked on projects for all employees order by ssn.

Hint: Note that even if SSN is not working in any project, it is there in the output with NULL value

-----------+------------+
| ssn | sum(hours) |
+-----------+------------+
| 123456789 | 40.00 |
| 333445555 | 40.00 |
| 453453453 | 40.00 |
| 666884444 | 40.00 |
| 888665555 | NULL |
| 987654321 | 35.00 |
| 987987987 | 40.00 |
| 999887777 | 40.00 |
+-----------+------------+
8 rows in set (0.00 sec)

Answer: 

The correct answer is: select ssn,sum(hours) from employee e left join works_on w on e.ssn = w.essn group by ssn order by ssn.

172.16.201.202/moodle/mod/quiz/review.php?attempt=14289&cmid=14758 9/13
07/08/2024, 10:44 Mock SQL Quiz (Not for grading)

Question 18
Correct

Mark 1.00 out of 1.00

Show the minimum salary of employees in the Administration department

+-------------+

| min(salary) |

+-------------+

| 25000 |

+-------------+

Answer: select min(salary) from employee where dno='4'; 

The correct answer is: select min(salary) from employee where dno=(select dnumber from department where dname = 'Administration').

Question 19

Correct

Mark 1.00 out of 1.00

Show the department id and count of employees in each department who have a salary > 30000 order by dno.

+------+------------+

| dno | count(ssn) |

+------+------------+

| 1| 1|

| 4| 1|

| 5| 2|

+------+------------+

Answer: select dno,count(ssn) from employee where salary>30000 group by dno order by dno; 

The correct answer is: select dno,count(ssn) from employee where salary > 30000 group by dno order by dno.

172.16.201.202/moodle/mod/quiz/review.php?attempt=14289&cmid=14758 10/13
07/08/2024, 10:44 Mock SQL Quiz (Not for grading)

Question 20
Correct

Mark 1.00 out of 1.00

Show the ssn of employees who have more than 1 dependent order by ssn

+-----------+

| essn |

+-----------+

| 123456789 |

| 333445555 |

+-----------+

Answer: select essn from dependent group by essn having count(essn)>1 order by essn; 

The correct answer is: select essn from dependent group by essn having count(essn)>1 order by essn.

Question 21

Correct

Mark 1.00 out of 1.00

Show the ssn and number of projects worked on by each employee for employees working on more than one project order by ssn

+-----------+------------+

| essn | count(pno) |

+-----------+------------+

| 123456789 | 2|

| 333445555 | 4|

| 453453453 | 2|
| 987654321 | 2|

| 987987987 | 2|

| 999887777 | 2|

+-----------+------------+

Answer: select essn,count(Pno) from works_on group by essn having count(Pno)>1 order by essn; 

The correct answer is: select essn,count(pno) from works_on group by essn having count(pno) > 1 order by essn.

172.16.201.202/moodle/mod/quiz/review.php?attempt=14289&cmid=14758 11/13
07/08/2024, 10:44 Mock SQL Quiz (Not for grading)

Question 22
Correct

Mark 1.00 out of 1.00

Show ssn,first name and department name they belong to for all employees order by ssn

+-----------+----------+----------------+

| ssn | fname | dname |

+-----------+----------+----------------+

| 123456789 | John | Research |

| 333445555 | Fanklin | Research |

| 453453453 | Joyce | Research |

| 666884444 | Ramesh | Research |

| 888665555 | James | Headquarters |

| 987654321 | Jennifer | Administration |

| 987987987 | Ahmad | Administration |

| 999887777 | Alicia | Administration |

+-----------+----------+----------------+

Answer: select employee.ssn,employee.fname,department.dname from employee join department on employee.Dno=dep

The correct answer is: select ssn,fname,dname from employee,department where dno=dnumber order by ssn.

Question 23

Correct

Mark 1.00 out of 1.00

Show ssn and first name of all employees whose departments are based at Houston order by ssn

+-----------+---------+

| ssn | fname |

+-----------+---------+

| 123456789 | John |

| 333445555 | Fanklin |

| 453453453 | Joyce |

| 666884444 | Ramesh |

| 888665555 | James |

+-----------+---------+

Answer: select ssn,fname from employee where dno in (1,5) order by ssn; 

The correct answer is: select ssn,fname from employee,dept_locations where dno=dnumber and dlocation = 'Houston' order by ssn.

172.16.201.202/moodle/mod/quiz/review.php?attempt=14289&cmid=14758 12/13
07/08/2024, 10:44 Mock SQL Quiz (Not for grading)

Question 24
Correct

Mark 1.00 out of 1.00

Show the last name of all employees who have female dependents order by last name.

+-------+
| lname |
+-------+
| Wong |
+-------+
1 row in set (0.01 sec)

Answer: select distinct lname from employee join dependent on employee.ssn=dependent.essn where dependent.sex='F 

The correct answer is: select lname from employee where ssn in (select essn from dependent where sex = 'F') order by lname;.

◄ Announcements

Jump to...

172.16.201.202/moodle/mod/quiz/review.php?attempt=14289&cmid=14758 13/13

You might also like