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

Data Base For Further Queries

The document provides examples of SQL queries to retrieve and analyze data from employee and department tables. It includes queries to select data, aggregate functions to calculate totals and averages, grouping and filtering on fields like department, gender, salary range, and more. The queries demonstrate common operations for analyzing and reporting on the data in the tables.

Uploaded by

Parveen Mittal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

Data Base For Further Queries

The document provides examples of SQL queries to retrieve and analyze data from employee and department tables. It includes queries to select data, aggregate functions to calculate totals and averages, grouping and filtering on fields like department, gender, salary range, and more. The queries demonstrate common operations for analyzing and reporting on the data in the tables.

Uploaded by

Parveen Mittal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1) For creating a Department Table

create table departments (

department varchar(100),

division varchar(100),

primary key (department)

);

2) Inserting Data in the Table

insert into

departments

values ('Clothing','Home');

Data Base For Further Queries

3)Select everything From Employees table

Select * from employees;


4) Selecting all the employees from Employees table working in ‘Sports’ department

Select *

From employees

Where department = ‘Sports’;

5) Select employees who have salary less then 40000 and should be working in ‘Clothing ‘ or “Pharmecy”
Department

Select *

from employees

where (department = ‘Clothing’ OR department = “pharmacy”) and salary<40000;

6) Select Employee whose don’t have emails

Select *

from employees

where email IS NULL;

7) Employees who have emails

Select *

from employees

where email IS NOT NULL;

8)Employees who have salary >=80000 and <=100000

Select *

from employees where salary between 80000 and 100000


9) Return first_name and email of femal employee whose salary greater then 110000 and working in
‘Tools’ department

Select first_name ,email

from employees

where department =’Tools’

and gender =’F’

and salary>110000;

10) Select employee first-name who were hired between two specific dates

Select first_name ,hire_date

from employees

where hire_date between '2005-10-05' and '2010-09-19';

11)Select name Of Employee

Select first_name || ” ” || last_name full_name

From employees

12)Concatenation Clause

Select first_name || “ ” || last_name , (salary>140000)

From employees Order by salary desc;

13)Aggregate Functions

SELECT MAX(salary) FROM employees;


Select max(salary), min(salary)

,(min(salary)+max(salary))/2 as wrong_average_one ,

round(avg(salary)) , count(employee_id) as numberOfEmployee,

Sum(salary) as totalSalary

from employees;

14) find the total salary paid by each department

Select SUM(salary),

department

from employees Group By department;

15)Total employee working for each department

Select count(*) numberOfEmployees Group By department;

16)find the number of (male and female ) employees in each department

Select count(*),

gender,

Department

from employees

Group by

Department , gender

order by department

17)Find Similar first name and count in the employees

Select first_name,

count(*) from employees group by first_name order by count(*) DESC;


18) Find the domin name of employees

Select count(*),

substring(email, position('@'in email)+1 ) as domains

from employees group by domains order by count(*) desc

19) find min max avg salary by Male ,female and region

20) Selecting from a query

Select a.first_name name from (select * from employees where salary>150000) a;

You might also like