这个查询如何工作? [英] How this query works ?

查看:115
本文介绍了这个查询如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道b发生了多少次。

能否解释一下这个查询。这会很有帮助

谢谢!



我尝试过:



INSERT INTO tblname

values('abbcbbcbbb')



select name,len(name)-len (替换(姓名,'b',''))/ len('b')来自#temp

Go

- 7

i just wanted find the how many times b has occurred.
Can you please explain this query. it would be helpful
Thanks !

What I have tried:

INSERT INTO tblname
values ('abbcbbcbbb')

select name, len(name)-len(replace(name,'b',''))/len('b') from #temp
Go
--7

推荐答案

一点一点地分解......



len(name)= 10

replace(name,'b','')='acc'

len('acc')= 3

10 - 3 = 7



基本上,您的替换会删除所有字母'b'。所以剩下的就是那些不是'b'的字母。原件(包括'b')和替换件(不包括'b')之间的长度差异是'b'的数量。



除由len('b')是不必要的...因为,这只是1 ...而除以1什么都不做。
Just break it down bit by bit...

len(name) = 10
replace(name,'b','') = 'acc'
len('acc') = 3
10 - 3 = 7

Basically, your "replace" removes all of the letters 'b'. So, all that remains are the letters that are NOT 'b'. The difference in length between the original (which includes 'b') and replacement (which does not include 'b') is the number of 'b's.

The divide by len('b') is unnecessary...since, that is simply 1...and dividing by 1 does nothing.


这篇关于这个查询如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆