Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

DBMSSRGC Employee

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

CREATE TABLE employee (

employee_id INT(6) NOT NULL PRIMARY KEY,

first_name VARCHAR(20) DEFAULT NULL,

last_name VARCHAR(20) NOT NULL,

email VARCHAR(25) NOT NULL,

phone_number VARCHAR(50) DEFAULT NULL,

hire_date DATE NOT NULL,

job_id VARCHAR(10) NOT NULL,

salary DECIMAL(8,2) DEFAULT NULL,

commission_pct DECIMAL(2,2) DEFAULT NULL,

manager_id INT(6) DEFAULT NULL,

department_id INT(4) DEFAULT NULL

);

Query::

INSERT INTO employee (employee_id, first_name, last_name, email, phone_number, hire_date,


job_id, salary, commission_pct, manager_id, department_id) VALUES

(1, 'John', 'Doe', 'john.doe@example.com', '123-456-7890', '2022-01-01', 'IT_PROG', 60000.00, NULL,


101, 10),

(2, 'Jane', 'Smith', 'jane.smith@example.com', '234-567-8901', '2022-02-01', 'HR_REP', 50000.00, 0.10,


102, 20),

(3, 'Emily', 'Johnson', 'emily.johnson@example.com', '345-678-9012', '2022-03-01', 'FIN_ANALYST',


55000.00, 0.15, 103, 30),

(4, 'Michael', 'Brown', 'michael.brown@example.com', '456-789-0123', '2022-04-01', 'SALES_REP',


45000.00, 0.05, 104, 40),

(5, 'Jessica', 'Williams', 'jessica.williams@example.com', '567-890-1234', '2022-05-01', 'IT_PROG',


62000.00, NULL, 105, 10);

Fatch records form the table


--------------------------------------
ques 1. Get the all employee details of employee and display the specific information

SELECT employee_id,first_name,last_name FROM employee;


Ques2. Write a query to display the employee name , job and annual salary for all employee.

SELECT CONCAT(first_name, ' ', last_name) AS employee_name,

job_id AS job,

salary * 12 AS annual_salary

FROM employee;

Ques3. Write a sql query to get the total number of employee working in the company.

Select count(*)

from employee

Ques4. Write query to get the total salary being paid to all employees.

SELECT SUM(salary) AS total_salary

FROM employee;

Ques5. Write a SQL query to get the maximum and minimum salary from the employee table.

SELECT

MAX(salary) AS max_salary,

MIN(salary) AS min_salary

FROM employee;

Ques 6. Write a SQL query to display the name of the employee in order to earning from lowest salary
to highest.

SELECT

CONCAT(first_name, ' ', last_name) AS employee_name, salary

FROM

employee

ORDER BY salary ASC;

Ques 7. Write a SQL query to display the name of the employee in order to earning from highest salary
to lowest .
SELECT

CONCAT(first_name, ' ', last_name) AS employee_name, salary

FROM

employee

ORDER BY salary desc;

Ques 8. Write a Oracle SQL query to display the name of the employees in
order to alphabetically ascending order

SELECT

CONCAT(first_name, ' ', last_name) AS employee_name

FROM

employee

ORDER BY

First_name ASC,

Ques 9. Write a Oracle SQL query to display employee id, name,


department no, salary of the employees. The output first based
on the employee name in ascending order, for unique name
department will come in ascending order, and for same name and
department the highest salary will come first.

SELECT

employee_id,

CONCAT(first_name, ' ', last_name) AS employee_name,

department_id,

salary

FROM

employee

ORDER BY

CONCAT(first_name, ' ', last_name) ASC,


department_id ASC,

salary DESC;

Ques 10. Write a Oracle SQL query to display the name and their annual salary.
The result should contain those employees first who earning the highest
salary

SELECT

CONCAT(first_name, ' ', last_name) AS employee_name,

salary * 12 AS annual_salary

FROM

employee

ORDER BY

salary DESC;

Ques 11. Write a Oracle SQL query to display department id and total
number of employees working in each department.

SELECT department_id, COUNT(*) AS total_employees

FROM employee

GROUP BY department_id;

Ques 12. Write a Oracle SQL query to display the designation (job id) and
total number of employees working in each designation.

SELECT

job_id,

COUNT(*) AS total_employees

FROM

employee

GROUP BY

job_id;
Ques 13. Write a Oracle SQL query to display the department number and total
salary for each department.

SELECT

department_id,

SUM(salary) AS total_salary

FROM

employee

GROUP BY

department_id;

Ques 14 . Write a Oracle SQL query to display the department number and
maximum salary for each department.

SELECT

department_id,

SUM(salary) AS total_salary

FROM

employee

GROUP BY

department_id;

Ques 15. Write a Oracle SQL query to display the designations (job id) and
total salary allotted for each designation from the company.
SELECT

job_id,

SUM(salary) AS total_salary_allotted

FROM

employee

GROUP BY

job_id;

Ques 16. From the following tables write a SQL query to find the salesperson
and customer who reside in the same city. Return Salesman, cust_name and
city.

Sample table: salesman

salesman_id | name | city | commission


-------------+------------+----------+------------
5001 | James Hoog | New York | 0.15
5002 | Nail Knite | Paris | 0.13
5005 | Pit Alex | London | 0.11
5006 | Mc Lyon | Paris | 0.14
5007 | Paul Adam | Rome | 0.13
5003 | Lauson Hen | San Jose | 0.12

Ans.

SELECT

s.name AS salesman,

c.cust_name,

s.city
FROM

salesman s

JOIN salesman c ON s.city = c.city WHERE s.salesman_id <> c.salesman_id;

Ques 17. From the following table, create a view for those salespeople who
belong to the city of New York.

Sample table: salesman

salesman_id | name | city | commission


-------------+------------+----------+------------
5001 | James Hoog | New York | 0.15
5002 | Nail Knite | Paris | 0.13
5005 | Pit Alex | London | 0.11
5006 | Mc Lyon | Paris | 0.14
5007 | Paul Adam | Rome | 0.13
5003 | Lauson Hen | San Jose | 0.12

Ans.

CREATE VIEW salespeople_in_new_york AS

SELECT

salesman_id,

name,

city,

commission

FROM

salesman

WHERE

city = 'New York';

SELECT * FROM salespeople_in_new_york;

You might also like