答案 0 :(得分:0)
使用内部联接:
SELECT a.name, sum(1) FROM user a
inner join user b on a.id >= b.id and a.name=b.name
group by a.id
order by a.id
结果:
# name, sum(1)
'chamath', '1'
'chamath', '2'
'chanaka', '1'
'chanaka', '2'
'chanaka', '3'
'nuwan', '1'
'silva', '1'