向Oracle SQL和SQL添加字段会停止工作

时间:2014-11-26 15:13:54

标签: regex oracle oracle-sqldeveloper

我有以下可用的Oracle SQL。我想要做的就是在输出中添加一个字段,我不能让这个SQL工作:

这是我的信息:

table name: access_log
col name: activity 
value: Download file:/webdocs/data/groupXXX/case/03_28_54_9_0000011856.pdf 

现在这是我正在使用的SQL:

select   regexp_replace(activity, '^.*/(.*)/.*$', '\1') AS FILENAME,
COUNT   (regexp_replace(activity, '^.*/(.*)/.*$', '\1')) AS DOWNLOADS,
FROM access_log where id = 5339 and time_stamp BETWEEN TO_DATE ('2014/02/01', 'yyyy/mm/dd') AND TO_DATE ('2014/02/02', 'yyyy/mm/dd')
GROUP BY regexp_replace(activity, '^.*/(.*)/.*$', '\1')
ORDER BY DOWNLOADS DESC;

但是我想更改SQL以显示"活动"的完整值。一直到右边但我不能添加这个字段并保持SQL工作.. cna有人请帮助我..

1 个答案:

答案 0 :(得分:2)

select   regexp_replace(activity, '^.*/(.*)/.*$', '\1') AS FILENAME,
         COUNT(1) OVER ( PARTITION BY regexp_replace(activity, '^.*/(.*)/.*$', '\1')) AS DOWNLOADS,
         activity
FROM access_log
where id = 5339
  and time_stamp BETWEEN TO_DATE ('2014/02/01', 'yyyy/mm/dd') AND TO_DATE ('2014/02/02', 'yyyy/mm/dd')
ORDER BY DOWNLOADS DESC;

我们在这里使用COUNT()作为窗口函数方法。