How to select a substring in Oracle SQL up to a 4th type of character

advertisements

I am trying to find a way in oracle SQL to take all the text after the 4th "/" and count how many is match. I need to do this in one SQL statement..

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