select 具有多少个相同值的列

select a column with how many same value present

我的专栏中有字符串数据

------------
name 
------------
john-yolo    
john-yolo    
john-yolo    
felix-goran  
carine-carin
carine-carin

我想select用名字出现的次数来命名列

例如:

------------
name 
------------
john-yolo-1    
john-yolo-2  
john-yolo-3    
felix-goran-1  
carine-carin-1
carine-carin-2

我怎样才能生成这样的数据?

MariaDB 支持ROW_NUMBER

CREATE TABLE test
    (`name` varchar(12))
;
    
INSERT INTO test
    (`name`)
VALUES

    ('john-yolo'),
    ('john-yolo'),
    ('john-yolo'),
    ('felix-goran'),
    ('carine-carin'),
    ('carine-carin')
;
SELECT CONCAT(name,'-', ROW_NUMBER() OVER(PARTITION BY name)) as  name FROM test
| name           |
| :------------- |
| carine-carin-1 |
| carine-carin-2 |
| felix-goran-1  |
| john-yolo-1    |
| john-yolo-2    |
| john-yolo-3    |

db<>fiddle here