简体   繁体   English

计算每行SQL Server的一列中ASCII代码的总数

[英]Count the total number of ASCII code in a column for each row SQL Server

I currently have a table with a lot of ASCII code scattered through it. 我目前有一张桌子,上面散布着许多ASCII码。 I'm using the REPLACE operator to remove it but before I remove it I need to find the total of each different piece of ASCII code. 我正在使用REPLACE运算符删除它,但是在删除它之前,我需要找到每个不同的ASCII代码的总和。 My current code is almost working correctly but I run into an issue when ASCII code is right next to each other.... eg. 我当前的代码几乎可以正常工作,但是当ASCII代码彼此相邻时,我遇到了一个问题。 "48% of the registered voters, NOT 48% of citizens ==>> BIG ! HUGE DIFFERENCE."....My code below is only counting the ASCII code once not twice. “ 48%的注册选民,而不是48%的公民==>>大的巨大差异。” ....我的下面代码仅对ASCII码计数一次,而不是两次。 Any help to get around this issue would be appreciated. 任何解决此问题的帮助将不胜感激。 If you need any more info please ask. 如果您需要更多信息,请询问。

SELECT comments, COUNT(*) AS total FROM AE
WHERE comments like '%>%' 
GROUP BY comments  

If you want to count the number of times that a string appears: 如果要计算字符串出现的次数:

SELECT comments, 
       (length(replace(comments, '>' , 'X>')) - length(comments)) as NumOccurrences
FROM AE
WHERE comments like '%>%' ;

I'm not sure that '>' 我不确定'>' is the string you really want to search for. 是您真正想要搜索的字符串。 But the idea is pretty simple. 但是这个想法很简单。 Replace the string with a string one character longer and then use length() to count the frequency within the comment. 将字符串替换为一个更长的字符,然后使用length()计算注释中的频率。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM