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

MY SQL Pratical

The document provides SQL commands and queries for managing a database named 'test1', including creating and dropping the database, using wildcards for pattern matching, and various queries to retrieve employee records based on specific conditions. It covers listing employees based on salary, job titles, and other criteria, as well as using single and group functions to calculate totals and averages. Additionally, it includes examples of using SQL functions to manipulate and display employee data.

Uploaded by

ASK 011
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)
10 views

MY SQL Pratical

The document provides SQL commands and queries for managing a database named 'test1', including creating and dropping the database, using wildcards for pattern matching, and various queries to retrieve employee records based on specific conditions. It covers listing employees based on salary, job titles, and other criteria, as well as using single and group functions to calculate totals and averages. Additionally, it includes examples of using SQL functions to manipulate and display employee data.

Uploaded by

ASK 011
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/ 5

Single Tables Practical

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.

_ (Underscore): This wildcard matches any single character.


For example, if you use 'C_', it matches any two-character string starting
with 'C', like 'CA', 'CB', 'CC', and so on.

[] (Square Brackets): You can specify a character list within square


brackets to match any one of the listed characters.
For example, '[AEIOU]%' would match any string that starts with a vowel.

[^] (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.

1. To list all records with sal > 2000 and comm>200

2. To list all record with job=’Clerk’ or sal>2000

3. To list all the record with sal=1250 or 1100 or 2850


4. To list all employees with sal>1250 and <2850

5. To list all employees with name ends with AS

6. To list all employees with job starts with C and ends with K

7. To list all employees with job contains L at third position and


M at third last position

8. To list all the record with sal not equal to 1250 or 1100 or 2850

9. To list all employees with salnot >1250 and <2850


10. To list all employees with job starts with C , E at 3rd position and ends with K
11. To list all rows with comm is null
12. To list all employees with sal is null and name starts with ‘S’
13. To list all employees with job contains 5 characters
14. To list all employees with name contain ‘A’ at 1 position and job

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

Concat it with 2 to 4 characters in job and then concat it with ‘@mycompany.com’


2. List all employees who joined in September.
3. List the empno, name, and department number of the emp who have experience of 18 or more
years and sort them based on their experience.
4. Display the employee details who joined on 3rd of any month or any year
5. display all employees who joined between years 1981 to 1983.

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.

You might also like