0
Error is coming in Advance SQL. Please help me.
SELECT firstname,lastname,salary, CASE WHEN salary <=1500 THEN salary*0.1 WHEN salary <=2000 THEN (1500*0.1) + ((salary-1500)*0.2) ELSE (1500*0.1)+(500*0.2)+((salary-2000)*0.3) END AS tax FROM Employees ORDER BY lastname ASC; You are working on the Employees table, which stores the names and salaries of employees. You need to calculate the taxes for the salaries and output them as a new column. The tax percentage is based on the salary amount: 0 - 1500: 10% 1501 - 2000: 20% 2001+: 30% Output the firstname, lastname, salary and tax columns of the table, sorted by the lastname column in ascending order.
4 Réponses
+ 2
I believe it is the task from SQL Intermediate > Data Manipulations > CASE lesson.
The task says:
You are working on the Employees table, which stores the names and salaries of employees.
You need to calculate the taxes for the salaries and output them as a new column.
The tax percentage is based on the salary amount:
0 - 1500: 10%
1501 - 2000: 20%
2001+: 30%
Output the firstname, lastname, salary and tax columns of the table, sorted by the lastname column in ascending order.
First, there is no syntax error in your code, therefore you can compare your output to the expected output.
Second, why you calculate the tax where salary above 1500 like you wrote?
+ 4
What's the task?
What is the error?
+ 2
SELECT firstnane,lastname,salary,
CASE
WHEN salary < 1501 THEN ‘10%’
WHEN salary >= 1501 and salary < 2000 THEN ‘20%’
WHEN salary >= 2001 THEN ‘30%’
END AS tax
FROM Employees
ORDER BY lastname ASC;
They just wanted you to match the salary bracket with the tax percentage and output the tax percentage in a column called tax. So if you make between 0-1500 then thats 10%.
+ 1
SELECT
firstname,
lastname,
salary,
CASE
WHEN salary <= 1500 THEN salary * 0.1
WHEN salary <= 2000 THEN (1500 * 0.1) + ((salary - 1500) * 0.2)
ELSE (1500 * 0.1) + (500 * 0.2) + ((salary - 2000) * 0.3)
END AS tax
FROM
Employees
ORDER BY
lastname ASC;
Here a alternate