[英]MySQL - Count the number of occurrences according to pattern in a VARCHAR field?
我有一张这样的桌子:
> URL
> ------------------------------------------------
> http://www.example.com
> http://www.example.com/one
> http://www.example.com/one/two/abc.txt
> http://www.example.com/three/four
> http://www.example.com/five/six/seven/def.txt
我想知道是否可以使用单个SQL查询来计算URL模式的出现并输出如下结果:
> URL PATTERN | COUNT
> --------------------------------------------------------------------------
> http://www.example.com/ | 5
> http://www.example.com/one/ | 2
> http://www.example.com/one/two/ | 1
> http://www.example.com/three/ | 1
> http://www.example.com/three/four/ | 1
> http://www.example.com/five/ | 1
> http://www.example.com/five/six/ | 1
> http://www.example.com/five/six/seven/ | 1
可以用SQL(MySQL)编写吗?
谢谢。
例如 :
update table_b set
count = (select count(url)
from table_a where url like "http://www.example.com/%")
where url_pattern = "http://www.example.com/"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.