简体   繁体   English

如何在Oracle SQL中选择子字符串(最多4个字符)

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

相关问题 如何在 Oracle SQL 中选择特定字符的子字符串? - How to Select a substring in Oracle SQL up to a specific character? 如何在Oracle SQL中选择子字符串 - How to Select a substring in Oracle SQL Select substring 在 Oracle SQL 到特定字符 - Select substring in Oracle SQL up to a specific character 如何在Oracle表的varchar列中的第2个和第4个char之后插入“/” - How to Insert '/' after 2nd and 4th char in varchar column of an Oracle table MySQL 将第四个表添加到 SELECT 弄乱了结果 - MySQL adding a 4th table to SELECT messes up results 如何在 Oracle SQL 中按顺序匹配当前和上个月的日期?(例如 1-jun as monday 与 4th jun monday 匹配) - How to match days for current and previous months sequentially in Oracle SQL?( e.g. 1-jun as monday is matched with 4th jun of monday) 如何在ORACLE中选择SUBSTRING - How Select SUBSTRING in ORACLE 在SQL Server中,如何选择第4行? - In SQL Server, how to pick top 4th row? 如何 substring 从 ORACLE SQL 中用点分隔的字符串中的最后两个标记(如果仅存在 4 和 5 个标记) - How to substring last two tokens from a string separated by dot in ORACLE SQL if only 4 and 5th tokens exists 如何仅在Oracle SQL中选择特定长度的子字符串 - How to Select a substring in Oracle SQL for specific length only
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM