简体   繁体   中英

Replace numbers by symbols SQL

I'm currently struggling.. I'm trying to convert values (Salarys) to * (stars) That means for 3000 it should give me *** as Result. Per 1000 should one * be made. Can anyone help me out?

Edit: My current solution (not working)

SELECT SUBSTR(LAST_NAME, 0,8) as h, round(SALARY, -3) FROM EMPLOYEES

So I already rounded on 1000, but how do I change it to Stars??

Try something like

SELECT REPEAT('*', FLOOR(Salary / 1000));

Simply divide your salary with 1000, then round so you have no decimals and then you repeat * x-times.

EDIT (depending on the comment):

SELECT SUBSTR(LAST_NAME, 0, 8) AS h, REPEAT('*', FLOOR(Salary / 1000))
FROM EMPLOYEES 
WHERE SALARY <> 0;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM