Leetcode Problem 1468. Calculate Salaries

1468. Calculate Salaries

Leetcode Solutions

Using CASE and JOIN to Calculate Taxed Salaries

  • Start by creating a subquery that selects the company_id and the maximum salary for each company from the Salaries table.
  • Use a CASE statement within the subquery to determine the tax rate based on the maximum salary.
  • Join the subquery with the original Salaries table on company_id.
  • Use another CASE statement to calculate the taxed salary for each employee by applying the tax rate to their salary.
  • Use the ROUND function to round the taxed salary to the nearest integer.
  • Select the required columns (company_id, employee_id, employee_name, and the calculated taxed salary) for the final output.
erDiagram
    Salaries {
        int company_id
        int employee_id
        varchar employee_name
        int salary
        company_id employee_id PK
    }

Using Common Table Expression (CTE) and CASE Statement

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...