CREATE function [dbo].[GetCharIndexNum](@findstring varchar(max),@string varchar(max))
returns int
AS
BEGIN
declare @location int , --要找的字符位置
@num int --要找的字符出现的次数
set @num =0
set @location = charindex (@findstring,@string)
while @location >0 ---字符串中存在要找的字符
begin
set @num =@num +1
set @string =substring(@string,@location+1,len(@string))
set @location = charindex (@findstring,@string)
end
return @num
END
--举个例子调用这个标量值函数 select [dbo].[GetCharIndexNum]('5','abc5ab5')
返回值2,5这个字符出现了2次
mysql中怎么统计某字段里某个字符的个数select
字段名,
count(*)
from
表
group
by
字段名
用count(*)函数来统计,返回匹配指定条件的行数。
例如有个表名称为demos,那么统计行数可以写:select count(*) from demos;
后面可以加限制条件,例如统计val大于3的记录行数:select count(*) from demos where val>3
扩展资料:
MySQL COUNT(*)
The COUNT(*) function returns the number of rows in a result set returned by a SELECT statement. TheCOUNT(*) function counts rows that contain no-NULL and NULL values.
COUNT(*) 语法
SELECT COUNT(*) FROM table_name
参考资料:MySQL官网-MySQL COUNT
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)