Sunteți pe pagina 1din 5

The given tables employee, job and answer the following questions with

SQL commands Consider.

TABLE – EMPLOYEE

EMPNO NAME DOB NATIVEPLACE HOBBY SEX


123 Amit 1965-01-23 Delhi Music M
127 Manoj 1976-12-12 Mumbai Writing M
124 Abay 1975-08- 11 Allahabad Music M
125 Shiksha 1977-12-13 Mumbai Swimming F
128 Arjun 1974-03-10 Pune Gardening M
126 Poojha 1980-06-14 Hyderabad Sports F
122 Ashwini 1981-10-18 Chennai Chess F
129 Ramesh 1981-10-28 Chennai Swimming M
130 Keshav 1977-01-09 Bangalore Swimming M
131 Krithika 1976-09-24 Agra Music F

TABLE – JOB

SNO AREA APTDATE BASIC ALLOWANCE RETDATE DEPT


123 Agra 2006-01-25 5000 1500 2026-01-27 Marketing
127 Mathura 2006-12-22 6000 1700 2026-12-22 Finance
124 Agra 2006-08-19 5500 1200 2027-08-19 Marketing
125 Delhi 2004-04-14 8500 2200 2018-04-14 Sales
128 Pune 2008-03-13 7500 1400 2028-03-13 Sales
126 Bangalore 2005-06-15 3500 1000 2025-06-15 Hr
122 Chennai 2003-04-23 12000 2000 2023-04-23 Hr
129 Mumbai 2003-06-12 9000 2000 2023-12-19 Sales
SQL QUERIES:

1. Display all the employees whose native place is “Mumbai” in the descending
order of their hobby.

Select *from employee where nativeplace=’Mumbai’ order by hobby desc;

Emp no Name Dob Nativeplace Hobby Sex


127 Manoj 1976-12-12 Mumbai Writing M
125 Shiksha 1977-12-13 Mumbai Swimming F

2. Print the name, basic, allowance and the net salary for these employee where
the name start with A, where net salary is calculated as basic+allowance.

Select name, basic, allowance, basic+allowance as “netsal” from job,


employee where employee.empno = job.sno and name like ‘a%’;

Name Basic Allowance Netsal


Amit 5000 1500 6500
Abay 5500 1200 6700
Arjun 7500 1400 8900
Ashwini 12000 2000 14000

3. Give the total salary spent for the male and female employees.

Select sex, sum(basic+allowance) from employee, job where empno=sno


group by sex;

Sex Basic+Allowance
F 29200
M 40800

4. Display the name, nativeplace and date of birth of the eldest employee in the
organization.

Select name, nativeplace, dob from employee where dob= Select min(date)
from employee;

Name Nativeplace Dob


Amit Delhi 1965-01-23
5. Find the total salary expenses of these employees whose retired date is after
20 Jan 2023.
Select sum(basic+allowance) as ‘Salary Expenses’ from job where retdate >
‘2023-01-20’;
Salary Expenses
59300

6. Print name, nativeplace, basic of those employees whose area is the


nativeplace.
Select name, nativeplace, basic from employee, job where empno=sno and
‘area’=’nativeplace';

Name Nativeplace Basic


Arjun Pune 7500
Ashwini Chennai 12000

7. Display the number of employees department wise, if the basic salary of that
department’s employees are more than 10000.
Select count(*), dept from job group by dept having sum(basic)>10000;

Count(*) Dept
2 Finance
2 Hr
2 Marketing
3 Sales

8.Find the appointment date of the first employee, the retirement date of the last
employee and the number of records of every departments where the basic
salary is more than 8000.
Select dept, min(aptdate),max(retdate),count(*) from job where
basic>8000 group by dept;

Dept Min Max Count


Finance 2003-07-12 2005-07-12 1
Hr 2003-04-23 2023-04-23 1
Sales 2003-12-19 2023-2-19 2
9. Add a new record in the table employee table.

Insert into employee values(132,’mahesh’,’1980-10-12’,’haridwar’,’chess’,’m’);

Empno Name Dob Nativeplace Hobby Sex


123 Amit 1965-01-23 Delhi Music M
127 Manoj 1976-02-12 Mumbai Writing M
124 Abay 1975-08-11 Allahabad Music M
125 Shiksha 1977-12-13 Mumbai Swimming F
128 Arjun 1947-03-10 Pune Gardening M
126 Pooja 1980-06-14 Hyderabad Sports F
122 Ashwini 1981-10-18 Chennai Chess F
129 Ramesh 1981-10-28 Chennai Swimming M
130 Kesha 1977-01-09 Bangalore Gardening M
131 Krithika 1976-09-24 Agra Music F
132 Mahesh 1980-10-12 Haridwar Chess M

10.Create a view named V1 which contains name, dob, hobby from the table
Employee.

Create view V1 as (select name, dob, hobby from Employee);

Name Dob Hobby


Manoj 1976-12-12 Writing
Shiksha 1977-12-13 Swimming
Arjun 1974-03-10 Gardening
Pooja 1980-06-14 Sports
Ashwini 1981-10-18 Chess
Ramesh 1981-10-25 Swimming
Keshav 1977-01-09 Gardening
Mahesh 1980-10-12 Chess
GIVE THE OUTPUTS FOR THE FOLLOWING COMMANDS
1. Select distinct hobby from employee;
Hobby
Writing
Swimming
Gardening
Sports
Chess

2. Select count(*), dept from job group by dept;

Count(*) Dept
2 Finance
2 Hr
2 Marketing
3 Sales

3. Select name, sno, basic from employee, job where eno=sno and basic
between 5000 and 10000;

Name Sno Basic


Manoj 127 6000
Shiksha 125 8500
Arjun 128 7500
Ramesh 129 9000
4. Select avg(basic) from employee, job where eno=sno and area is
(‘Agra’,’Delhi’);
Avg(basic)
8500.0000

5. Select nativeplace, count(*) from employee group by nativeplace;

Nativeplace Count(*) Nativeplace Count(*)


Bangalore 1 Pune 1
Allahabad 1 agra 1
Delhi 1
Chennai 2
Haridwar 1
Hyderabad 1
Mumbai 2

S-ar putea să vă placă și