DBMS Lab 4
DBMS Lab 4
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 ;
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' ;