我试图在oracle SQL中找到一种方法来获取第4个" /"之后的所有文本。并计算有多少匹配。我需要在一个SQL语句中执行此操作..
table name: access_log
col name: download
col name: time-stamp
value: Download file:/webdocs/data/groupXXX/case/03_28_54_9_0000011856.pdf
我想结束
case/03_28_54_9_0000011856.pdf
然后计算多少场比赛?可以这样做吗?
答案 0 :(得分:1)
我会这样做:
SELECT
SUBSTR(DOWNLOAD, INSTR(DOWNLOAD, '/', 1, 4) + 1) AS FILENAME,
COUNT(SUBSTR(DOWNLOAD, INSTR(DOWNLOAD, '/', 1, 4) + 1)) AS DOWNLOADS
FROM ACCESS_LOG
GROUP BY SUBSTR(DOWNLOAD, INSTR(DOWNLOAD, '/', 1, 4) + 1)
ORDER BY DOWNLOADS DESC;
返回此结果集:
| FILENAME | DOWNLOADS | |--------------------------------|-----------| | case/03_28_54_9_0000011856.pdf | 3 | | case/04_28_54_9_0000011856.pdf | 2 |
有关演示,请参阅此处:SQL Fiddle
答案 1 :(得分:0)
试
SELECT SUBSTR(download, INSTR(download, '/', 1, 4)+1) FROM access_log
获得总尝试次数:
SELECT COUNT(*) , T1.file_name
FROM (SELECT SUBSTR(download, INSTR(download, '/', 1, 4)+1) as file_name
FROM access_log) T1
GROUP BY T1.file_name ;