Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
113 views

Queries Related With Employee Schema

The document contains 24 SQL queries related to an employee schema. The queries retrieve employee information like name, address, department, salary, projects, etc. and perform aggregates, filters, joins on the employee and department tables.

Uploaded by

Ankur Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views

Queries Related With Employee Schema

The document contains 24 SQL queries related to an employee schema. The queries retrieve employee information like name, address, department, salary, projects, etc. and perform aggregates, filters, joins on the employee and department tables.

Uploaded by

Ankur Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Queries related with Employee schema.

Q1. Find all the name of employees.

SELECT name
FROM employee;

Q2. Find the name, address of employees who works for department number
C001.

SELECT name, address


FROM employee
WHERE deptid=’C001’;

Q3. Find the EID, start date of the employees who works for project number 201
or project number 301.

SELECT eid, startdate


FROM join
WHERE pcode=201 or pcode=301;

Q4. Find the name, EID of employees whose salary is greater than 20,000.

SELECT eid, name


FROM employee
WHERE salary>20000;

Q5. Retrieve all information of employees whose salary is greater than 20,000.

SELECT *
FROM employee
WHERE salary>20000;

Q6. Show the resulting salaries if every employee is given a 10 present raise.

SELECT name, salary*1.1


FROM employee;
Q7. Retrieve name and salary of employee whose salary is between 20000 and
28000.

SELECT name salary


FROM employee
WHERE salary BETWEEN 20000 AND 28000;

Q8. Retrieve the distinct values of the salary of employee.

SELECT DISTINCT salary


FROM employee;

Q9. Retrieve the name, address of all employees.

SELECT name, address


FROM employee, department;

Q10. Retrieve all possible combinations of EID and DName is the database.

SELECT eid, dname


FROM employee, department;

Q11.Find the name of the department that employee Rajendra Gupta works for.

SELECT dname
FROM employee e, department d
WHERE e.deptid=d.deptid AND name=’Rahul Gupta’;

Q12. Find the name of the employees whose address is in ‘Ram’.

SELECT name
FROM employee
WHERE address LIKE ‘%Ram%’;

Q13. Retrieve a list of employees and the projects they are working on, order the
result by project’s name, within each project, order by employee’s name.

SELECT e.name, p.name


FROM employee e, project p, join j
WHERE j.pcode=p.pcode AND e.eid=j.eid
ORDER BY p.name, e.name;
Q14. For each department, find the number of employee’s works for that
department.

SELECT deptid, COUNT (eid)


FROM employee
GROUP BY deptid;

Q15. For each department with more than 8 employees, retrieve the department
number and the corresponding number of employees.

SELECT deptid, COUNT (eid)


FROM employee
GROUP BY deptid
HAVING COUNT (eid)>8;

Q16. Find the average salary of all employees in the Animation department.

SELECT AVG (salary)


FROM employee e, department d
WHERE e.deptid=d.deptid AND dname=’ Animation’;

Q17. Find the number of employee’s works for department Management.

SELECT COUNT (eid)


FROM employee e, department d
WHERE e.deptid=d.deptid AND dname=’ Management’;

Q18.count the number of salary values in the database.

SELECT COUNT (DISTINCT Salary)


FROM employee;

Q19. Find all employees with null values for Address.

SELECT name
FROM employee
WHERE address IS null;
Q20. Retrieve the identification number, name and address of employees who
work for department number C001, S123, R101.

SELECT eid, name, address


FROM employee
WHERE deptid IN (C001, S123, R101);

Q21. Retrieve the identification number of employees who work in the same
project that employee ‘601’ works in.

SELECT eid
FROM join
WHERE pcode IN (SELECT pcode FROM join WHERE eid=’601’);

Q22. Retrieve the identification number and the name of employees who have the
highest salary in the company.

SELECT eid, name


FROM employee
WHERE salary>=ALL(SELECT salary FROM employee);

Q23. Retrieve the name of employees whose salary is greater than at least one
employee of the department number L345.

SELECT name
FROM employee
WHERE salary>ANY(SELECT salary FROM employee WHERE deptid=’L345’);

Q24. Retrieve the name of each employee who has a department with the same
name as the employee.

SELECT name
FROM employee e
WHERE EXISTS
(SELECT * FROM department d WHERE d.eid=e.eid AND name=d.dname);

You might also like