Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

MySQL String Exercises: Display the first name and salary for all employees

MySQL String: Exercise-15 with Solution

Write a query to display the first name and salary for all employees. Format the salary to be 10 characters long, left-padded with the $ symbol. Label the column SALARY.

Sample table: employees


Code:

SELECT first_name,
LPAD(salary, 10, '$') SALARY
FROM employees;

Sample Output:

 first_name			SALARY
Steven				$$24000.00
Neena				$$17000.00
Lex				$$17000.00
Alexander			$$$9000.00
Bruce				$$$6000.00
David				$$$4800.00
Valli				$$$4800.00
Diana				$$$4200.00
Nancy				$$12000.00
Daniel				$$$9000.00
John				$$$8200.00
Ismael				$$$7700.00
Jose Manuel			$$$7800.00
Luis				$$$6900.00
Den				$$11000.00
Alexander			$$$3100.00
Shelli				$$$2900.00
Sigal				$$$2800.00
Guy				$$$2600.00
Karen				$$$2500.00
Matthew				$$$8000.00
Adam				$$$8200.00
Payam				$$$7900.00
Shanta				$$$6500.00
Kevin				$$$5800.00
Julia				$$$3200.00
Irene				$$$2700.00
James				$$$2400.00
Steven				$$$2200.00
Laura				$$$3300.00
Mozhe				$$$2800.00
James				$$$2500.00
TJ				$$$2100.00
Jason				$$$3300.00
Michael				$$$2900.00
Ki				$$$2400.00
Hazel				$$$2200.00
Renske				$$$3600.00
Stephen				$$$3200.00
John				$$$2700.00
Joshua				$$$2500.00
Trenna				$$$3500.00
Curtis				$$$3100.00
Randall				$$$2600.00
Peter				$$$2500.00
John				$$14000.00
Karen				$$13500.00
Alberto				$$12000.00
Gerald				$$11000.00
Eleni				$$10500.00
Peter				$$10000.00
David				$$$9500.00
Peter				$$$9000.00
Christopher			$$$8000.00
Nanette				$$$7500.00
Oliver				$$$7000.00
Janette				$$10000.00
Patrick				$$$9500.00
Allan				$$$9000.00
Lindsey				$$$8000.00
Louise				$$$7500.00
Sarath				$$$7000.00
Clara				$$10500.00
Danielle			$$$9500.00
Mattea				$$$7200.00
David				$$$6800.00
Sundar				$$$6400.00
Amit				$$$6200.00
Lisa				$$11500.00
Harrison			$$10000.00
Tayler				$$$9600.00
William				$$$7400.00
Elizabeth			$$$7300.00
Sundita				$$$6100.00
Ellen				$$11000.00
Alyssa				$$$8800.00
Jonathon			$$$8600.00
Jack				$$$8400.00
Kimberely			$$$7000.00
Charles				$$$6200.00
Winston				$$$3200.00
Jean				$$$3100.00
Martha				$$$2500.00
Girard				$$$2800.00
Nandita				$$$4200.00
Alexis				$$$4100.00
Julia				$$$3400.00
Anthony				$$$3000.00
Kelly				$$$3800.00
Jennifer			$$$3600.00
Timothy				$$$2900.00
Randall				$$$2500.00
Sarah				$$$4000.00
Britney				$$$3900.00
Samuel				$$$3200.00
Vance				$$$2800.00
Alana				$$$3100.00
Kevin				$$$3000.00
Donald				$$$2600.00
Douglas				$$$2600.00
Jennifer			$$$4400.00
Michael				$$13000.00
Pat				$$$6000.00
Susan				$$$6500.00
Hermann				$$10000.00
Shelley				$$12000.00
William				$$$8300.00

MySQL Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous:Write a query that displays the first name and the length of the first name for all employees whose name starts with the letters 'A', 'J' or 'M'.
Next:Write a query to display the first eight characters of the employees' first names and indicates the amounts of their salaries with '$' sign. Each '$' sign signifies a thousand dollars. Sort the data in descending order of salary.

What is the difficulty level of this exercise?