-- create a table
CREATE TABLE employees (
id INTEGER PRIMARY KEY NOT NULL,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
num_years INTEGER NOT NULL,
satisfaction DECIMAL(25,5) NOT NULL);
-- insert some values
INSERT INTO employees VALUES (1,'Harry','Potter',7,0.999999);
INSERT INTO employees VALUES (2,'Draco','Malefoy',7,0.6799999);
INSERT INTO employees VALUES (3,'Hermione','Granger',7,0.978);
INSERT INTO employees VALUES (4,'Fred','Weasley',5,0.499999999);
INSERT INTO employees VALUES (5,'Mimi','Geignarde',2,0.1);
INSERT INTO employees VALUES (6,'Ronald','Weasley',7,0.999999);
INSERT INTO employees VALUES (7,'Test','Test',1,0.1589);
-- SOLUTION
select CONCAT(SUBSTR(UPPER(first_name),1, 1),SUBSTR(UPPER(last_name),1,1),SUBSTR(UPPER(last_name),LENGTH(last_name),LENGTH(last_name)),'-',
CAST(satisfaction AS DECIMAL(5,2)),CASE
WHEN num_years >=3 THEN '-x'
ELSE ''
END) AS employee_code
FROM employees
ORDER BY satisfaction desc;
#For each employee, return a code containing the following elements separated by a - :
#First letter of the first_name together with the first and last letter of the last_name, in capital letters.
#satisfaction (keeping only two digits after the decimal point). The character "x" if the employee's seniority (num_years ) is greater than or equal to 3 years.
#Requirements Expected column: employee_code. Sort the rows by satisfaction descending
To embed this project on your website, copy the following code and paste it into your website's HTML: