我有一个名为BODY的列表。在此列中,您可以找到某处有某个数字的文本(您不知道数字出现的位置)。文本可能在几行中相同但数字不同。我想对相同的文本进行分组,但省略不同的数字。对于以下数据,我应该有2组,每组3个元素。如何按类似的方式分组?
'here is some text 888697885 more text in row'
'here is some text 234234234 more text in row'
'here is some text 345345345 more text in row'
'here 234234234 is some different text in row'
'here 234234456 is some different text in row'
'here 554645645 is some different text in row'
答案 0 :(得分:1)
SELECT COUNT(REPLACE(details, LEFT(SUBSTRING(details, PATINDEX('%[0-9.-]%', details), 8000), PATINDEX('%[^0-9.-]%', SUBSTRING(details, PATINDEX('%[0-9.-]%', details), 8000) + 'X') -1) ,''))
FROM supportContacts
GROUP BY REPLACE(details, LEFT(SUBSTRING(details, PATINDEX('%[0-9.-]%', details), 8000), PATINDEX('%[^0-9.-]%', SUBSTRING(details, PATINDEX('%[0-9.-]%', details), 8000) + 'X') -1) ,'');
只需替换列名和表名。