Query Practice
Query Practice
+-------------+-------------+-------------+-------------+
| SUM(salary) | MAX(salary) | MIN(salary) | AVG(salary) |
+-------------+-------------+-------------+-------------+
| 281000 | 55000 | 25000 | 35125.0000 |
+-------------+-------------+-------------+-------------+
---------------------------------------------------------------------
2 find the sum of the salaries of all employees of the research dept as well as the
max salary, min salary and the avg salary in this dept
----------------------------------------------------------------------
3 Retriev the total number in companies and the total number of employess in the
reseach department
5 retriev the names of all employess who have two or more dependents
mysql> select fname,lname from employee where (select count(*) from
employee,dependent where ssn=essn) >=2;
+----------+---------+
| fname | lname |
+----------+---------+
| John | Smith |
| Franklin | Wong |
| Joyce | English |
| Ramesh | Narayan |
| James | Borg |
| Jennifer | Wallace |
| Ahmad | Jabbar |
| Alicia | Zelaya |
+----------+---------+
8 rows in set (0.03 sec)
----------------------------------------------------------------------
6 for each dept, retriev the department number, number pf employes in it and the
avg salary of each dept
mysql> select Dno,COUNT(*),AVG(salary) from employee GROUP BY dno;
+-----+----------+-------------+
| Dno | COUNT(*) | AVG(salary) |
+-----+----------+-------------+
| 1 | 1 | 55000.0000 |
| 4 | 3 | 31000.0000 |
| 5 | 4 | 33250.0000 |
+-----+----------+-------------+
----------------------------------------------------------------------
7 retrieve the project number, name and numbe of employess who work for that
project
mysql> select pnumber,pname,count(*) from works_on,project where pno=pnumber GROUP
BY pname,pnumber;
+---------+-----------------+----------+
| pnumber | pname | count(*) |
+---------+-----------------+----------+
| 1 | ProductX | 2 |
| 2 | ProductY | 3 |
| 3 | ProductZ | 2 |
| 10 | Computerization | 3 |
| 20 | Reorganization | 3 |
| 30 | Newbenefits | 3 |
+---------+-----------------+----------+
--------------------------------------------------------------------
8 retrieve the project number, name and count of employees where a project is taken
by 2 or more employee
select pnumber,pname,count(*) from works_on,project where pno=pnumber GROUP BY
pname,pnumber HAVING count(*)>=2;+---------+-----------------+----------+
| pnumber | pname | count(*) |
+---------+-----------------+----------+
| 10 | Computerization | 3 |
| 30 | Newbenefits | 3 |
| 1 | ProductX | 2 |
| 2 | ProductY | 3 |
| 3 | ProductZ | 2 |
| 20 | Reorganization | 3 |
+---------+-----------------+----------+
_____________________________________________________________________
9 for each project reetirev the project number, name and number of employees of
dept 5 who work for that project
mysql> select pnumber,pname,COUNT(*) from project,works_on,employee WHERE
pno=pnumber AND ssn=essn AND dnum=5 GROUP BY pname,pnumber;
+---------+-----------------+----------+
| pnumber | pname | COUNT(*) |
+---------+-----------------+----------+
| 1 | ProductX | 2 |
| 2 | ProductY | 3 |
| 3 | ProductZ | 2 |
+---------+-----------------+----------+
------------------------------------------------------------------
10 for each dept, that has more than 5 employees, retrieve the dept number and the
number of its' employess who has salary more than 40000
mysql> select dno,COUNT(*) from employee WHERE salary>40000 AND dno IN (SELECT dno
FROM employee GROUP BY dno HAVING COUNT(*)>5) GROUP BY dno;
Empty set (0.02 sec)
---------------------------------------------------------------------
ER Diagram
triggers & assertion
virtual table
mcqs view(virtual table)
ram baugh book for UML
T1- 3q*5marks
tables parametes attiributes mentioned, perform operations-10 marks.....no data
insertion only attribute creation
5 marks for OOPS-UML.