php - display result of field using *** at first 3 characters when condition is met in sql query -
i have table :
username | status aaa | pending bbbbbbb | pending cccc | cancelled dddddddd | cancelled eeeeee | approved ffffff | approved
the result i'd show @ end :
status | username pending | ***aaa, ***bbbb cancelled | ***cccc, ***ddddd approved | ***eee, ***fff
i've tried select query
select distinct status,case when length(username) >=6 group_concat(replace(username, left( username, 3 ) , '***') separator ', ') else group_concat('***',username separator ', ') end username table group status
however, result of bbbbbbb
query won't work because there 3 characters username @ first row. so, result become :
status | username pending | ***aaa, ***bbbbbbb // wrong (it should ***aaa , ***bbbb) cancelled | ***cccc, ***ddddd // true approved | ***eee, ***fff // true
how perform query show result expected?. thank before
as understand, need move case
inside group_concat
. this:
select distinct status, group_concat( case when length(username) >= 6 replace(username, left(username, 3), '***') else concat('***', username) end separator ', ' )as username table group status
Comments
Post a Comment