substitute employee salary by '*' [message #290527] |
Sat, 29 December 2007 08:34 |
emadnabil
Messages: 179 Registered: August 2007
|
Senior Member |
|
|
Hii all
I want to make a select statment of the employee table
that shows the employee first name and
'*' if the salary > 1000
'**' if the salary > 2000
'***' if the salary > 3000
etc...
so the result be like that
employee name salary
emad *
bebo *
omda **
gemy ***
lolo ***
memy ***
lala ****
|
|
|
Re: substitute employee salary by '*' [message #290532 is a reply to message #290527] |
Sat, 29 December 2007 09:21 |
SnippetyJoe
Messages: 63 Registered: March 2007 Location: Toronto, Canada
|
Member |
|
|
column sal_graph format a15
select
ename,
sal,
lpad( '*', trunc( sal/1000 ), '*' ) sal_graph
from
emp
;
ENAME SAL SAL_GRAPH
---------- ---------- ---------------
SMITH 800
ALLEN 1600 *
WARD 1250 *
JONES 2975 **
MARTIN 1250 *
BLAKE 2850 **
CLARK 2450 **
SCOTT 3000 ***
KING 5000 *****
TURNER 1500 *
ADAMS 1100 *
JAMES 950
FORD 3000 ***
MILLER 1300 *
14 rows selected.
--
Joe Fuda
SQL Snippets
|
|
|
|
Re: substitute employee salary by '*' [message #290591 is a reply to message #290532] |
Sun, 30 December 2007 03:47 |
|
Michel Cadot
Messages: 68716 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
[slighty off topic] Until puzzle forum arrives, here's a trick I often used to get a quick look of data.
If you want a graph of the ratio of each salary to the greatest one:
SQL> column sal_graph format a10
SQL> column ratio_to_max format a52 heading " Ratio to max salary (*=2% of max)"
SQL> select ename, sal, lpad( '*', trunc(sal/1000), '*') sal_graph,
2 rpad(rpad('|',1+round(50*sal/max(sal) over ()),'*'),51)||'|' ratio_to_max
3 from emp
4 /
ENAME SAL SAL_GRAPH Ratio to max salary (*=2% of max)
---------- ---------- ---------- ----------------------------------------------------
SMITH 800 |******** |
ALLEN 1600 * |**************** |
WARD 1250 * |************* |
JONES 2975 ** |****************************** |
MARTIN 1250 * |************* |
BLAKE 2850 ** |***************************** |
CLARK 2450 ** |************************* |
SCOTT 3000 *** |****************************** |
KING 5000 ***** |**************************************************|
TURNER 1500 * |*************** |
ADAMS 1100 * |*********** |
JAMES 950 |********** |
FORD 3000 *** |****************************** |
MILLER 1300 * |************* |
14 rows selected.
Regards
Michel
[Updated on: Sun, 30 December 2007 03:51] Report message to a moderator
|
|
|
|
|
|