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 leading zeros before maximum and minimum salary

MySQL String: Exercise-4 with Solution

Write a query to display leading zeros before maximum and minimum salary.

Sample table: jobs


Code:

SELECT job_id,  LPAD( max_salary, 7, '0') ' Max Salary',
LPAD( min_salary, 7, '0') ' Min Salary' 
FROM jobs;

Sample Output:

job_id		Max Salary	Min Salary
AD_PRES		0040000		0020000
AD_VP		0030000		0015000
AD_ASST		0006000		0003000
FI_MGR		0016000		0008200
FI_ACCOUNT	0009000		0004200
AC_MGR		0016000		0008200
AC_ACCOUNT	0009000		0004200
SA_MAN		0020000		0010000
SA_REP		0012000		0006000
PU_MAN		0015000		0008000
PU_CLERK	0005500		0002500
ST_MAN		0008500		0005500
ST_CLERK	0005000		0002000
SH_CLERK	0005500		0002500
IT_PROG		0010000		0004000
MK_MAN		0015000		0009000
MK_REP		0009000		0004000
HR_REP		0009000		0004000
PR_REP		0010500		0004500

MySQL Code Editor:

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

Previous:Write a query to get the details of the employees where the length of the first name greater than or equal to 8.
Next:Write a query to append '@example.com' to email field.

What is the difficulty level of this exercise?