﻿ PostgreSQL String Function: Fill the maximum and minimum salary with leading asterisks until it is becoming a seven character string - w3resource

# PostgreSQL String() Function: Fill the maximum and minimum salary with leading asterisks until it is becoming a seven character string

4. Write a query to fill the maximum and minimum salary with leading asterisks whether these two columns does not contain a seven digit number.

Sample Solution:

Code:

``````SELECT job_id,  LPAD(trim(to_char(max_salary,'9999999')),7,'*') "Max Salary" ,
FROM jobs;
``````

Sample table: jobs

Output:

```pg_exercises=# SELECT job_id,  LPAD(trim(to_char(max_salary,'9999999')),7,'*') "Max Salary" ,
pg_exercises-# FROM jobs;
job_id   | Max Salary | Min Salary
------------+------------+------------
FI_MGR     | **16000    | ***8200
FI_ACCOUNT | ***9000    | ***4200
AC_MGR     | **16000    | ***8200
AC_ACCOUNT | ***9000    | ***4200
SA_MAN     | **20000    | **10000
SA_REP     | **12000    | ***6000
PU_MAN     | **15000    | ***8000
PU_CLERK   | ***5500    | ***2500
ST_MAN     | ***8500    | ***5500
ST_CLERK   | ***5000    | ***2000
SH_CLERK   | ***5500    | ***2500
IT_PROG    | **10000    | ***4000
MK_MAN     | **15000    | ***9000
MK_REP     | ***9000    | ***4000
HR_REP     | ***9000    | ***4000
PR_REP     | **10500    | ***4500
(19 rows)
```

## Practice Online

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

What is the difficulty level of this exercise?

﻿

New Content: Composer: Dependency manager for PHP, R Programming