Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
24 views

Oracle SQL Practice Queries

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)
24 views

Oracle SQL Practice Queries

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/ 1

Oracle SQL Practice Queries

Query 1: Second Highest Salary

SELECT Name, Salary


FROM Employees
WHERE Salary = (
SELECT MAX(Salary)
FROM Employees
WHERE Salary < (SELECT MAX(Salary) FROM Employees)
);

Query 2: Departments with More Than 2 Employees

SELECT DepartmentID, COUNT(*) AS EmployeeCount


FROM Employees
GROUP BY DepartmentID
HAVING COUNT(*) > 2;

Query 3: Departments with Above-Average Salary

SELECT d.DepartmentName, AVG(e.Salary) AS AvgSalary


FROM Employees e
JOIN Departments d ON e.DepartmentID = d.DepartmentID
GROUP BY d.DepartmentName
HAVING AVG(e.Salary) > (SELECT AVG(Salary) FROM Employees);

Query 4: Employees Above the 75th Percentile in Their Department

SELECT Name, Salary, DepartmentID


FROM (
SELECT Name, Salary, DepartmentID, PERCENT_RANK() OVER (PARTITION BY
DepartmentID ORDER BY Salary) AS Percentile
FROM Employees
)
WHERE Percentile >= 0.75;

You might also like