MY SQL Pratical
MY SQL Pratical
Create database:
create database test1;
drop database test1;
use database test1;
show database test1;
wild cards
% : matches any sequence of characters (including zero characters).
For example, if you use 'C%', it matches any string that starts with 'C',
such as 'Clerk', 'Coordinator', 'CFO', and so on.
[^] (Caret inside Square Brackets): To negate a character list, use a caret
(^) inside square brackets.
For example, '[^0-9]%' matches any string that doesn't start with a digit.
6. To list all employees with job starts with C and ends with K
8. To list all the record with sal not equal to 1250 or 1100 or 2850
Contains 5 characters
Q2. Solve the following
1. Retrieve the details (Name, Salary and dept no) of the emp who are working in department code
20, 30 and 40.
2. Display the total salary of all employees . Total salary will be calculated as sal+comm+sal*0.10
3. List the Name and job of the emp who have joined before 1 jan 1986 and whose salary range is
between 1200and 2500. Display the columns with user defined Column headers.
4. List the empno, name, and department number of the emp works under manager with id 7698
5. List the name, job, and salary of the emp who are working in departments 10 and 30.
6. Display name concatenated with dept code separated by comma and space. Name the column as
‘Emp info’.
7. Display the emp details who do not have manager.
8. Write a query which will display name, department no and date of joining of all employee who
were joined January 1, 1981 and March 31, 1983. Sort it based on date of joining (ascending).
select ename,deptno,hiredate
from emp
where hiredate between '1981-1-1' and '1983-3-31'
order by hiredate
9. Display the employee details where the job contains word ‘AGE’ anywhere in the Job
11. List the details of the employee , whose names start with ‘A’ and end with ‘S’ or whose names
contains N as the second or third character, and ending with either ‘N’ or ‘S’.
select *
from emp
where ename like ‘A%S’ or ename like ‘_N%N’ or ename like ‘_N%S’ or ename like ‘__N%N’ or
ename like ‘__N%S’
or
select *
from emp
where ename REGEXP ‘^A.*S$| ^..?N.*[NS]$‘
12. List the names of the emp having ‘_’ character in their name.
Single Row functions
1. To list all employees and their email, to generate email use 2 to 5 characters from ename
Group functions
6. Display the Highest, Lowest, Total & Average salary of all employee. Label the columns Maximum,
Minimum, Total and Average respectively for each Department. Also round the result to the nearest
whole number.
7. Display Department no and number of managers working in that department. Label the column as
‘Total Number of Managers’ for each department.
8. Get the Department number, and sum of Salary of all non managers where the sum is greater
than 20000.