- 1

SQL - CONCAT & AS

Hello world, can someone help understanding whats wrong with my code? The error message is that apparently the «salary» column doesn't exist but it exist in the problem. See for yourself. The problem : The AS Keyword You are given the following staff table:contentImageThe salary shown in the table is monthly. Each employee receives a bonus once a year. The bonus for each employee is equal to their years of experience multiplied by 500. ***I can't copy/past the image but here are the 5 columns : «fisrtname», «lastname», «salary», «department», «experience» Write a query to output the firstname and lastname columns into one column named fullname separated by space, and the total annual salary for each employee keeping in mind bonuses named 'total'. Sort by the 'total' column. Use the AS keyword and the CONCAT function! Here's my code : SELECT CONCAT ('fistname',',''lastname') AS fullname, CONCAT ((salary*12)+(experience*500)) AS total ORDER BY total;

27th Aug 2021, 2:35 PM
Raphaël Leblanc
Raphaël Leblanc - avatar
6 odpowiedzi
+ 2
I think your calculation is correct, but as I understand it, CONCAT was meant to glue string values together. Therefore I don't think you need to use CONCAT for the annual bonus calculation result, as it is a numeric calculation ... (salary * 12 + (experience * 500)) AS total ... ORDER BY total; I'd probably try something like that
27th Aug 2021, 3:19 PM
Ipang
+ 3
That was it. Thank you so muchIpang! The new and correct code : SELECT CONCAT (firstname,' ',lastname) AS fullname, (salary*12 + (experience*500)) AS total FROM staff ORDER BY total
27th Aug 2021, 3:23 PM
Raphaël Leblanc
Raphaël Leblanc - avatar
+ 2
My solution: SELECT CONCAT (firstname,' ',lastname) AS fullname, (salary*12 + (experience*500)) AS total FROM staff ORDER BY total
10th Nov 2022, 8:23 AM
Pooja Patel
Pooja Patel - avatar
+ 1
May I ask why you use CONCAT for calculated annual bonus? guessing by the field name 'salary', I would assume it contains numeric value.
27th Aug 2021, 2:55 PM
Ipang
+ 1
Ipang, I want to merge the 2 columns by adding both columns values into 1 columns name «total». Here's my new code : SELECT CONCAT (firstname,' ',lastname) AS fullname, CONCAT (salary*12,'+',experience*500) AS total from staff ORDER BY total You're right I shouldn't CONCAT the «salary» and «experience», but how do I merge the to columns values into 1 columns 1 value?
27th Aug 2021, 3:06 PM
Raphaël Leblanc
Raphaël Leblanc - avatar
0
SELECT CONCAT (firstname,' ',lastname) AS fullname, CONCAT ((salary*12)+(experience*500)) AS total from staff ORDER BY total
19th Sep 2022, 3:37 PM
Amir Reza Taghavi