他们是同一个专栏
Name-Category
A-SL
B-SL
C-SL
A-SL
A-SL
C-SL
现在在我的脚本中,我将它们分组在类别中,但我想计算它们在查询中出现的次数。请看下面:
Customer-Line#
A-1 (means its the first time it occurs)
A-2 (means its the second time it occurs)
A-3 (means its the third time it occurs)
....so on
----------
B-1 (means its the first time it occurs)
----------
C-1 (means its the first time it occurs)
C-2 (means its the second time it occurs)
抱歉造成混乱,希望每个人都清楚。
谢谢你,
您可以使用row_number()为同名客户添加号码:
select name + '-' + cast(row_number() over (
partition by name order by id) as varchar(24))
from YourTable
如果仅在有多个客户时才需要该号码,您可以使用case when ... then ... end表达:
select name +
case
when count(*) over (partition by name) = 1 then ''
else '-' + cast(row_number() over (
partition by name order by id) as varchar(24))
end
from YourTable
SQL Fiddle 中的示例。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)