0% found this document useful (0 votes)
8 views14 pages

Lab 02 - SELECT

The document contains a series of SQL queries designed to retrieve specific information from an Employees table. Queries include displaying employee details, filtering by hire dates, salaries, and specific name patterns, as well as formatting output. Each query is structured to meet different data retrieval requirements, such as sorting, concatenation, and conditional filtering.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views14 pages

Lab 02 - SELECT

The document contains a series of SQL queries designed to retrieve specific information from an Employees table. Queries include displaying employee details, filtering by hire dates, salaries, and specific name patterns, as well as formatting output. Each query is structured to meet different data retrieval requirements, such as sorting, concatenation, and conditional filtering.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

1.

Create a query to display the first name, last name, hire

date, salary, and salary after a raise of 10%. Name the last

column (salary after a raise) heading as “ANNUAL_SAL”

(Employees table).
SELECT
first_name,
last_name,
hire_date,
salary,
salary * 1.10 AS ANNUAL_SAL
FROM
Employees;
2. Create a query to display the unique manager numbers

from Employees table.

SELECT DISTINCT manager_id


FROM Employees;
3. Create a query to display the last name concatenated with the first
name, separated by space, and the telephone number concatenated
with the email address, separated by hyphen. Name the column
headings “FULL_NAME” and “CONTACT_DETAILS” respectively
(Employees tables).
SELECT
CONCAT(LastName, ' ', FirstName) AS FULL_NAME,
CONCAT(TelephoneNumber, '-', EmailAddress) AS
CONTACT_DETAILS
FROM
Employees;
4. Write a query in SQL to list the employees who joined in

the month of JUNE

SELECT *
FROM Employees
WHERE MONTH(JoinDate) = 6;
5. Write a query in SQL to list the employees of department

id 50 or 110 joined in the year 2000.

SELECT *
FROM Employees
WHERE DepartmentID IN (50, 110)
AND YEAR(JoinDate) = 2000;
6. Write a SQL query to find those employees who were

hired between November 2th, 2007 and July 10th, 2009.

Return full name (first and last), job id and hire date

SELECT
CONCAT(FirstName, ' ', LastName) AS Full_Name,
JobID,
HireDate
FROM
Employees
WHERE
HireDate BETWEEN '2007-11-02' AND '2009-07-10';
7. Write a query in SQL to list the details of the employees in

ascending order to the employee_id and descending order to

the manager_id

SELECT *
FROM Employees
ORDER BY EmployeeID ASC, ManagerID DESC;
8. write a SQL query to find employees whose first names

contain the letters D, S, or N. Sort the result-set in

descending order by salary. Return all fields

SELECT *
FROM Employees
WHERE FirstName LIKE '%D%'
OR FirstName LIKE '%S%'
OR FirstName LIKE '%N%'
ORDER BY Salary DESC;
9. Write a query in SQL to list the employees with Hire date

in the format like Feb 22, 1991

SELECT
EmployeeID,
FirstName,
LastName,
DATE_FORMAT(HireDate, '%b %d, %Y') AS Hire_Date
FROM
Employees;
10. Write a query in SQL to list the employees with a salary

range between 2000 to 5000 without any commission.

SELECT *
FROM Employees
WHERE Salary BETWEEN 2000 AND 5000
AND (Commission IS NULL OR Commission = 0);
11. Write a query to display FIRST names of employees,

whose the third letter is “a”

SELECT FirstName
FROM Employees
WHERE SUBSTRING(FirstName, 3, 1) = 'a';
12. Displays the FIRST names of employees with letter “a” and “e” in

their names

SELECT FirstName
FROM Employees
WHERE FirstName LIKE '%a%'
AND FirstName LIKE '%e%';
13. Write a SQL query to find the employees whose first name ends

with the letter ‘m’. Return the first and last name, and salary

SELECT FirstName, LastName, Salary


FROM Employees
WHERE FirstName LIKE '%m';
14. Write a SQL query to find those employees whose salaries are not

between 3000 and 8000 (Begin and end values are included). Sort the

result-set in ascending order by the full name (first and last). Return full

name and salary.


SELECT
CONCAT(FirstName, ' ', LastName) AS Full_Name,
Salary
FROM
Employees
WHERE
Salary NOT BETWEEN 3000 AND 8000
ORDER BY
Full_Name ASC;

You might also like