Can anyone tell me why this code is wrong 🤒 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Can anyone tell me why this code is wrong 🤒

SELECT firstname, lastname, salary, CASE WHEN salary <= 1500 THEN '0.1' WHEN salary >= 1501 AND salary <= 2000 THEN '0.2' ELSE '0.3' END AS tax FROM Employees ORDER BY lastname ASC;

6th Mar 2024, 11:58 AM
Chathurika Dewmini
Chathurika Dewmini - avatar
6 Answers
+ 2
you are supposed to multiply the salary by the tax. also, sort the result by lastname in ascending order.
6th Mar 2024, 12:11 PM
Bob_Li
Bob_Li - avatar
+ 2
Thank you to everyone who supports me. It's very simple, but I was confused. I got the right code 😊😇 SELECT firstname, lastname, salary, CASE WHEN salary <= 1500 THEN salary * 0.1 WHEN salary >= 1501 AND salary <= 2000 THEN salary * 0.2 ELSE salary * 0.3 END AS tax FROM Employees ORDER BY lastname ASC;
6th Mar 2024, 1:08 PM
Chathurika Dewmini
Chathurika Dewmini - avatar
+ 1
How about review the previous chapter "Math & Aggregate Functions"? The very first page shows how to have a selected field calculated on the fly.
6th Mar 2024, 12:45 PM
Wong Hei Ming
Wong Hei Ming - avatar
+ 1
instead of just displaying '0.1','0.2' and '0.3' compute salary*0.1, salary*0.2 and salary*0.3
6th Mar 2024, 12:53 PM
Bob_Li
Bob_Li - avatar
0
Bob_Li I I changed my code according to your advice as ORDER BY lastname ASC; But I don't know how multiple the salary by tax?????
6th Mar 2024, 12:38 PM
Chathurika Dewmini
Chathurika Dewmini - avatar
0
You are suppose to select the column and not the row inside the column
7th Mar 2024, 7:56 PM
Xperience Piro
Xperience Piro - avatar