mysql SQL query for 'The account number is masked by an asterisk(*) except for the last 4 digits in both previous and new value.'

eqqqjvef  于 2022-12-22  发布在  Mysql
关注(0)|答案(2)|浏览(114)

table

ACC_NO      pre_val    New_val
123489432   123489432  123489435
123489532   123489532  123489435

I asked some of my friends but not getting how to write the sql query.

bgibtngc

bgibtngc1#

Extract the last 4 digits with RIGHT() and concatenate them with the asterisks that replace the first 5 digits.

SELECT ACC_NO, CONCAT('*****', RIGHT(pre_val, 4)) AS pre_val, CONCAT('*****', RIGHT(new_val, 4)) AS new_val
FROM yourTable
31moq8wy

31moq8wy2#

Your question is a bit unclear but, I guess you want something like that(?)

SELECT LPAD(RIGHT(ACC_NO, 4),9, "*");

相关问题