[英]How to Select a substring in Oracle SQL up to a 4th char tyoe
I am trying to find a way in oracle SQL to take all the text after the 4th "/" and count how many is match. 我试图在oracle SQL中找到一种方法来获取第4个“ /”之后的所有文本,并计算匹配的数目。 I need to do this in one SQL statement..
我需要在一条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
I am trying to end up with 我试图以
case/03_28_54_9_0000011856.pdf
then a count of how many matches? 那么算多少场比赛? can this be done?
可以做到吗?
I would go with this: 我会这样:
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;
It returns this resultset: 它返回以下结果集:
| FILENAME | DOWNLOADS | |--------------------------------|-----------| | case/03_28_54_9_0000011856.pdf | 3 | | case/04_28_54_9_0000011856.pdf | 2 |
For a demo see here: SQL Fiddle 有关演示,请参见此处: SQL Fiddle
try 尝试
SELECT SUBSTR(download, INSTR(download, '/', 1, 4)+1) FROM access_log
to get the total try: 得到总尝试:
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 ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.