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

Query Practice

Uploaded by

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

Query Practice

Uploaded by

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

1 find the sum of the salaries of all employees, the max salary, the min salary and

the avg salary

mysql> select SUM(salary),MAX(salary),MIN(salary),AVG(salary) from employee;

+-------------+-------------+-------------+-------------+
| 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

mysql> select SUM(salary),MAX(salary),MIN(salary),AVG(salary) from employee JOIN


department where Dno=Dnumber AND Dname="Research";
+-------------+-------------+-------------+-------------+
| SUM(salary) | MAX(salary) | MIN(salary) | AVG(salary) |
+-------------+-------------+-------------+-------------+
| 133000 | 40000 | 25000 | 33250.0000 |
+-------------+-------------+-------------+-------------+

mysql> select SUM(salary),MAX(salary),MIN(salary),AVG(salary) from employee JOIN


department where Dname="Research";
+-------------+-------------+-------------+-------------+
| SUM(salary) | MAX(salary) | MIN(salary) | AVG(salary) |
+-------------+-------------+-------------+-------------+
| 281000 | 55000 | 25000 | 35125.0000 |
+-------------+-------------+-------------+-------------+

----------------------------------------------------------------------

3 Retriev the total number in companies and the total number of employess in the
reseach department

mysql> select COUNT(*) from employee,department where Dno=Dnumber AND Dname=


"Research";
+----------+
| COUNT(*) |
+----------+
| 4 |
+----------+
----------------------------------------------------------------------

4 count the number of distinct salaries values in the databse


mysql> select COUNT( DISTINCT salary) from employee;
+-------------------------+
| COUNT( DISTINCT salary) |
+-------------------------+
| 6 |
+-------------------------+

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.

You might also like