簡體   English   中英

MySQL-根據VARCHAR字段中的模式計數出現次數?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM