SQL Queries for Employee Data Analysis
38 Questions
0 Views

SQL Queries for Employee Data Analysis

Created by
@BraveChalcedony9426

Questions and Answers

What information is displayed for Martin's manager's manager's department?

The department name and location.

Who is displayed in the list of employees with no commission in Chicago or Dallas?

Employees' manager number, job, and department number.

What details are shown for employees earning the maximum commission?

Employee details along with their annual salary.

Which employees qualify as earning commission in sales and were hired before the last hire?

<p>Employees in the sales department with non-null or non-zero commission.</p> Signup and view all the answers

What does the query about Ward's manager's manager return?

<p>All department names.</p> Signup and view all the answers

What is listed for employees whose salary is greater than the average clerk's salary?

<p>Their department names.</p> Signup and view all the answers

What does the record of the last employee with a 25% salary hike include?

<p>Details about the last employee record.</p> Signup and view all the answers

What is displayed for employees in the sales department who are managers?

<p>Their department number.</p> Signup and view all the answers

List the employees from the accounting department who earn more than the average salary of their department.

<p>Employees in the accounting department with salaries above the average can be identified using a SQL query that computes the average salary and filters based on that.</p> Signup and view all the answers

How would you display the location of employees who earn a commission?

<p>A SQL query can be used to select the location of employees where the commission is greater than zero.</p> Signup and view all the answers

Can you list employees who do not report to the president but have a commission and a salary higher than the maximum salary of clerks?

<p>To find these employees, a query must exclude those reporting to the president while filtering for commission and salary conditions.</p> Signup and view all the answers

What is the SQL query required to display employees whose salary is greater than the average salary of department 20?

<p>Use a query that calculates the average salary of department 20 and selects employees earning above that value.</p> Signup and view all the answers

Identify the location and department name of employees who are managers but earn less than clerks.

<p>A query is needed to select the location and department name of employees categorized as managers with a salary lower than clerks.</p> Signup and view all the answers

How can you display the average salary of all employees in the accounting department?

<p>An SQL query can be constructed to compute the average salary by filtering for the accounting department.</p> Signup and view all the answers

What should you include in a query to list employees whose name starts with 'S' and have a salary between 'ALLEN' and 'FORD'?

<p>The query should filter employees whose names start with 'S' and have salaries greater than 'ALLEN' and less than 'FORD'.</p> Signup and view all the answers

Display the maximum salary in the sales department.

<p>To find this, a SQL MAX function can be used to select the highest salary where the department is sales.</p> Signup and view all the answers

What should be displayed to find the department name of the employee with the maximum salary who has no reporting manager?

<p>The department name of the highest earning employee without a reporting manager should be displayed.</p> Signup and view all the answers

What information is needed to display the employee details who are reporting to Blake and have a commission?

<p>Employee details of those reporting to Blake with commission should be displayed, without using NULL criteria.</p> Signup and view all the answers

How do you list the names and locations of all the department names associated with salesman managers?

<p>By listing all deptname and loc for the employees who hold salesman manager positions.</p> Signup and view all the answers

What should be identified for employees who report to Blake, are clerks, and earn less than Martin's salary?

<p>The department name and location of clerks reporting to Blake with salaries lower than Martin's must be listed.</p> Signup and view all the answers

What condition must be met to find employees earning more than the maximum salary of all clerks and do not report to the president?

<p>They must have a salary greater than the maximum clerk salary and have a commission.</p> Signup and view all the answers

How can you identify employees who joined after four years of the first employee and have a salary less than Blake's?

<p>List employees with a join date more than four years after the first employee's and earning less than Blake.</p> Signup and view all the answers

What query would you write to display employee names with the minimum salary in the Research department?

<p>SELECT ENAME FROM EMPLOYEES WHERE SALARY = (SELECT MIN(SALARY) FROM EMPLOYEES WHERE DEPARTMENT = 'Research')</p> Signup and view all the answers

How would you list department names that have at least 3 employees?

<p>SELECT DEPARTMENT_NAME FROM DEPARTMENTS WHERE DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM EMPLOYEES GROUP BY DEPARTMENT_ID HAVING COUNT(*) &gt;= 3)</p> Signup and view all the answers

What is the query to find the employee name, job, and location of all managers working in Chicago?

<p>SELECT ENAME, JOB, LOCATION FROM EMPLOYEES WHERE JOB = 'Manager' AND LOCATION = 'Chicago'</p> Signup and view all the answers

What query would you construct to select the employee who earns the second maximum salary and works in Dallas?

<p>SELECT ENAME FROM EMPLOYEES WHERE SALARY = (SELECT DISTINCT SALARY FROM EMPLOYEES WHERE LOCATION = 'Dallas' ORDER BY SALARY DESC LIMIT 1 OFFSET 1)</p> Signup and view all the answers

How would you write a query to display employees from Sales and Research departments having at least 2 reporting employees?

<p>SELECT ENAME FROM EMPLOYEES WHERE DEPARTMENT IN ('Sales', 'Research') AND (SELECT COUNT(*) FROM EMPLOYEES AS R WHERE R.MANAGER_ID = EMPLOYEES.EMPLOYEE_ID) &gt;= 2</p> Signup and view all the answers

What is the SQL query to display names of employees who earn the highest salary in their respective jobs?

<p>SELECT ENAME FROM EMPLOYEES WHERE SALARY IN (SELECT MAX(SALARY) FROM EMPLOYEES GROUP BY JOB)</p> Signup and view all the answers

How would you find the location of the employee earning the maximum salary and has no reporting manager?

<p>SELECT LOCATION FROM EMPLOYEES WHERE SALARY = (SELECT MAX(SALARY) FROM EMPLOYEES) AND MANAGER_ID IS NULL</p> Signup and view all the answers

What query can be used to find the number of employees whose job is salesman working for New York and Chicago?

<p>SELECT COUNT(*) FROM EMPLOYEES WHERE JOB = 'Salesman' AND LOCATION IN ('New York', 'Chicago')</p> Signup and view all the answers

What query would you use to display the employee names who have the maximum salary in the department named 'ACCOUNTING'?

<p>SELECT emp_name FROM employees WHERE salary = (SELECT MAX(salary) FROM employees WHERE dept_name = 'ACCOUNTING')</p> Signup and view all the answers

How do you query to display all employees whose department names end with 'S'?

<p>SELECT * FROM employees WHERE dept_name LIKE '%S'</p> Signup and view all the answers

What is the query to display the locations of employees whose salary is the minimum but greater than 2000?

<p>SELECT location FROM employees WHERE salary = (SELECT MIN(salary) FROM employees WHERE salary &gt; 2000)</p> Signup and view all the answers

Which query will display the names of employees who are reporting to 'JONES'?

<p>SELECT emp_name FROM employees WHERE manager = 'JONES'</p> Signup and view all the answers

What query would you write to find department names with at least 3 salesmen?

<p>SELECT dept_name FROM employees WHERE job_title = 'SALESMAN' GROUP BY dept_name HAVING COUNT(*) &gt;= 3</p> Signup and view all the answers

How can you display employee names whose department has the second character as 'O'?

<p>SELECT emp_name FROM employees WHERE dept_name LIKE '_O%'</p> Signup and view all the answers

What is the SQL query to list employees whose salary is greater than that of 'MILLER'?

<p>SELECT emp_name FROM employees WHERE salary &gt; (SELECT salary FROM employees WHERE emp_name = 'MILLER')</p> Signup and view all the answers

Which query will display the department location for employees in the 'ACCOUNTING' department?

<p>SELECT location FROM employees WHERE dept_name = 'ACCOUNTING'</p> Signup and view all the answers

Study Notes

Subquery Questions Overview

  • Queries designed to retrieve specific employee and department data using subqueries.
  • Focus on varying conditions such as job titles, salaries, departments, locations, and reporting structures.

Employee Queries

  • Display employees whose department names end with 'S'.
  • Find employees receiving the maximum salary in the "ACCOUNTING" department.
  • Identify employees earning more than "MILLER".
  • List employees based in "CHICAGO" with zero commission.
  • Retrieve employees who joined after the first employee in the company and earn more than "BLAKE".

Salary and Commission

  • Find the department name of the employee earning the maximum salary with no reporting manager.
  • Count employees getting a salary less than the manager’s salary of "BLAKE".
  • Filter employees whose salary is between 1500 and 3000 and whose names don't start with 'S'.

Reporting Structure and Department Insights

  • List employees who do not directly report to the president and have a commission higher than the maximum salary of clerks.
  • Display department information of employees working in "NEW YORK".
  • Show departments with at least three salesmen or at most five employees.

Location Queries

  • List locations of employees whose manager's salary exceeds 2000.
  • Present department names of employees earning commission or located in departments with clerks.

Job and Department Specific Queries

  • Display job titles and manager numbers for those working under "JONES".
  • Retrieve department names with at least one 'MANAGER'.
  • Identify department names having clerks or salesmen, focusing on structure and employee counts.

Data Records and Employment History

  • Display records of employees hired after certain dates or criteria, emphasizing engagement over time.
  • Show employees with certain conditions applied to reporting and salaries based on specific historical data.

Aggregate Functions and Maximum/Minimum Criteria

  • Find maximum and minimum salary across employees, highlighting the structure in relation to departments or jobs.
  • List average salaries and filter based on those averages to establish performance standards.

Miscellaneous

  • Highlight specific conditions such as employees not taking commissions, joined after certain dates, or filtering based on job titles containing specific letters.
  • Utilize subqueries strategically to gain insights into overall employee performance and departmental health.

Conclusion

  • Use of queries and subqueries to create a comprehensive picture of employee dynamics within the organization, utilizing salary, reporting, and department information.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Description

This quiz covers advanced SQL queries related to employee salary, reporting structures, and department information. Assess your understanding of how to extract specific employee details based on various criteria. Ideal for those looking to enhance their SQL skills in a corporate context.

More Quizzes Like This

SQL Queries Test - Generators 3.0
12 questions
SQL Queries for Filtering States
24 questions

SQL Queries for Filtering States

UnconditionalInterstellar7213 avatar
UnconditionalInterstellar7213
Use Quizgecko on...
Browser
Browser