Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

Sample table: jobs

+------------+---------------------------------+------------+------------+
| JOB_ID     | JOB_TITLE                       | MIN_SALARY | MAX_SALARY |
+------------+---------------------------------+------------+------------+
| AD_PRES    | President                       |      20000 |      40000 |
| AD_VP      | Administration Vice President   |      15000 |      30000 |
| AD_ASST    | Administration Assistant        |       3000 |       6000 |
| FI_MGR     | Finance Manager                 |       8200 |      16000 |
| FI_ACCOUNT | Accountant                      |       4200 |       9000 |
| AC_MGR     | Accounting Manager              |       8200 |      16000 |
| AC_ACCOUNT | Public Accountant               |       4200 |       9000 |
| SA_MAN     | Sales Manager                   |      10000 |      20000 |
| SA_REP     | Sales Representative            |       6000 |      12000 |
| PU_MAN     | Purchasing Manager              |       8000 |      15000 |
| PU_CLERK   | Purchasing Clerk                |       2500 |       5500 |
| ST_MAN     | Stock Manager                   |       5500 |       8500 |
| ST_CLERK   | Stock Clerk                     |       2000 |       5000 |
| SH_CLERK   | Shipping Clerk                  |       2500 |       5500 |
| IT_PROG    | Programmer                      |       4000 |      10000 |
| MK_MAN     | Marketing Manager               |       9000 |      15000 |
| MK_REP     | Marketing Representative        |       4000 |       9000 |
| HR_REP     | Human Resources Representative  |       4000 |       9000 |
| PR_REP     | Public Relations Representative |       4500 |      10500 |
+------------+---------------------------------+------------+------------+

Output:

pg_exercises=# SELECT job_id,  LPAD(trim(to_char(max_salary,'9999999')),7,'*') "Max Salary" ,
pg_exercises-# LPAD(trim(to_char(min_salary,'9999999')),7,'*') "Min Salary"
pg_exercises-# FROM jobs;
   job_id   | Max Salary | Min Salary
------------+------------+------------
 AD_PRES    | **40000    | **20000
 AD_VP      | **30000    | **15000
 AD_ASST    | ***6000    | ***3000
 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)

 

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now