我并不确切地知道该怎么称呼这个问题,所以如果标题令人困惑,请道歉。我正在尝试生成特定网站的用户活动摘要。此查询返回每种页面的总点击次数:
select
count(case when internal_handle = 'content' then 1 else null end) as CONTENT,
count(case when data = '/webapps/assessment/take/launch.jsp' then 1 else null end) as ASSESSMENTS,
count(case when internal_handle = 'discussion_board_entry' then 1 else null end) as DISCUSSIONS,
count(case when data = '/webapps/blackboard/execute/uploadAssignment' then 1 else null end) as BB_ASSIGNMENTS,
count(case when data = '/webapps/turn-plgnhndl-BBLEARN/links/submit.jsp' then 1 else null end) as TII_ASSIGNMENTS,
count(case when data = '/webapps/osv-kaltura-BBLEARN/jsp/courseGallery.jsp' then 1 else null end) as COURSE_GALLERY,
count(case when data = '/webapps/osc-BasicLTI-BBLEARN/frame.jsp' then 1 else null end) as ECHO_360,
count(case when internal_handle = 'check_grade' then 1 else null end) as MY_GRADES
from BBLEARN.ACTIVITY_ACCUMULATOR
where course_pk1 = (select pk1 from BBLEARN.course_main where course_id = '2014FA.BOS.PPB.445.A')
and user_pk1 in (select users_pk1 from BBLEARN.course_users where role = 'S' and crsmain_pk1 = course_pk1);
结果如下:
CONTENT,ASSESSMENTS,DISCUSSIONS,BB_ASSIGNMENTS,TII_ASSIGNMENTS,COURSE_GALLERY,ECHO_360,MY_GRADES
5787,954,335,0,0,0,837,222
但我的目标是将每个用户的点击次数分开。例如,我想要一个像:
这样的结果USER_PK1,CONTENT,ASSESSMENTS,DISCUSSIONS,BB_ASSIGNMENTS,TII_ASSIGNMENTS,COURSE_GALLERY,ECHO_360,MY_GRADES
USER_A,250,79,41,0,0,0,66,7
USER_B,144,89,82,0,0,0,24,0
USER_C,174,45,23,0,0,0,58,1
--etcetera
我可以想象迭代地运行上面的查询,但我对Oracle的熟悉程度不够高。我该怎么做呢?或者有更好的方法来获取我正在寻找的领域吗?
提前致谢!
答案 0 :(得分:3)
只需添加group by
:
select user_pk1,
count(case when internal_handle = 'content' then 1 else null end) as CONTENT,
count(case when data = '/webapps/assessment/take/launch.jsp' then 1 else null end) as ASSESSMENTS,
count(case when internal_handle = 'discussion_board_entry' then 1 else null end) as DISCUSSIONS,
count(case when data = '/webapps/blackboard/execute/uploadAssignment' then 1 else null end) as BB_ASSIGNMENTS,
count(case when data = '/webapps/turn-plgnhndl-BBLEARN/links/submit.jsp' then 1 else null end) as TII_ASSIGNMENTS,
count(case when data = '/webapps/osv-kaltura-BBLEARN/jsp/courseGallery.jsp' then 1 else null end) as COURSE_GALLERY,
count(case when data = '/webapps/osc-BasicLTI-BBLEARN/frame.jsp' then 1 else null end) as ECHO_360,
count(case when internal_handle = 'check_grade' then 1 else null end) as MY_GRADES
from BBLEARN.ACTIVITY_ACCUMULATOR
where course_pk1 = (select pk1 from BBLEARN.course_main where course_id = '2014FA.BOS.PPB.445.A') and
user_pk1 in (select users_pk1 from BBLEARN.course_users where role = 'S' and crsmain_pk1 = course_pk1)
group by user_pk1;
如果user_pk1
不是“user”的意思,那么您可能需要加入另一个表。