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

DBMS Lab 4

The document contains a series of SQL queries designed to extract specific information from an HR database. It includes queries to count employees by department, filter departments with a minimum number of employees, identify unique first names, and display employee names based on various criteria. Each query is prefaced with commands to select the database and tables before executing the SQL statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

DBMS Lab 4

The document contains a series of SQL queries designed to extract specific information from an HR database. It includes queries to count employees by department, filter departments with a minimum number of employees, identify unique first names, and display employee names based on various criteria. Each query is prefaced with commands to select the database and tables before executing the SQL statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

1.

Write a query to lists the number of employees in each


department.
show databases;
use hr;

show tables;
select * from employees;
select count(employee_id) as "Number of employees", department_id from employees
group by department_id ;
2. Write a query to display the department id where at least
5 employees should be in each department.
show databases;
use hr;

show tables;
select * from employees;
select department_id, count(employee_id) as "Employee" from employees group by
department_id having count(employee_id)>5;
3. Write a query to display all columns of those employees
who has first name is unique.
show databases;
use hr;

show tables;
select * from employees;
select distinct first_name, last_name from employees;
4. Write a SQL query to get name of employees containing
exactly four characters
show databases;
use hr;

show tables;
select * from employees;
select first_name, last_name from employees where first_name regexp '^....$' and
last_name regexp '^....$';
5. Write a query to display the list of employee names that
have letters ‘LA’ in their names.
show databases;
use hr;

show tables;
select * from employees;
select first_name from employees where first_name regexp 'LA';
6. Write a query to display names of those employees whose
first name starts with ‘A’ and ends with ‘N’.
show databases;
use hr;

show tables;
select * from employees;
select first_name from employees where first_name regexp '^a.*n$';
7. Write a query to display first names of all employees that
end with alphabet ‘N’
show databases;
use hr;

show tables;
select * from employees;
select first_name from employees where first_name regexp '^*n$';
8. Write a query to display FIRST_NAME, LASTNAME of all
employees whose first name starts with letter ‘A’.
show databases;
use hr;

show tables;
select * from employees;
select first_name,last_name from employees where first_name regexp '^A';
9. Write a query to display the number of employees with the
same job
show databases;
use hr;

show tables;
select * from employees;
select count(employee_id) as "Employees",job_id from employees group by job_id;
10. Display the manager number and the salary of the
lowest paid employee of that manager. Exclude anyone
whose manager is not known. Exclude any groups where
the minimum salary is 2000. Sort the output is descending
order of the salary
show databases;
use hr;

show tables;
select * from employees;
select manager_id, min(salary) from employees where manager_id is not null group
by manager_id having min(salary)>2000 order by min(salary) desc ;

11. Display the total number of employees who have no


commission.
show databases;
use hr;

show tables;
select * from employees;
select count(employee_id) from employees where not commission_pct regexp 'null' ;
12.Write a query to display FIRST_NAME, LASTNAME of all
employees whose first name small ‘t’

show databases;
use hr;

show tables;
select * from employees;
select lower(first_name), last_name from employees where lower(first_name) regexp
'^t' ;

You might also like