My approach : with cte as (select *,max(salary) over(partition by company_id) as max_salary from Salaries), cte_2 as ( select *,cast(case when max_salary 10000 then 49 else null end as float) / 100 as tax_rate from cte) select company_id,employee_id,employee_name, round(salary-(salary*tax_rate),0) as calculated_salary from cte_2;
We're subtracting the tax from the salary because tax is something that gets taken away from the employee's salary, not added to it. This helps us find the actual salary after tax. For example, if an employee's salary is $2000 and the tax rate is 24%, we subtract 24% from their salary like this: Actual Salary = Salary - (Tax * Salary).
Well explained Sneha!
Glad you found it helpful!
My approach :
with cte as (select *,max(salary) over(partition by company_id) as max_salary
from Salaries), cte_2 as (
select *,cast(case when max_salary 10000 then 49 else null end as float) / 100 as tax_rate
from cte)
select company_id,employee_id,employee_name,
round(salary-(salary*tax_rate),0) as calculated_salary
from
cte_2;
we should do salary + tax right, to get the salary after applying taxes, why are we subtracting can you please explain
We are deducting taxable amount from the total salary
We're subtracting the tax from the salary because tax is something that gets taken away from the employee's salary, not added to it. This helps us find the actual salary after tax.
For example, if an employee's salary is $2000 and the tax rate is 24%, we subtract 24% from their salary like this:
Actual Salary = Salary - (Tax * Salary).