我的要求是从两个表REPORT_API_USAGE
&中获取详细信息。 REPORT_API_PAGES
。我需要从TERMNAME
和COUNT(TERMNAME)
获取REPORT_API_USAGE
,COUNT(CTYPE)
,event
和download
来自REPORT_API_PAGES
。两个表都有公共字段termid
。要求是获取TERMNAME
,COUNT(TERMNAME)
相关事件和文件下载。
TERMID
24
REPORT_API_PAGES
CTYPE
download
只有Face-to-Face Learning 1 0 1
Face-to-Face Learning
。所以结果应该是TERMID'
我有. I have added an event and document with reference of
页面. Once i viewed
24 page,
面对面学习will store the page hit value in
面对面学习table. Once the event and document pages are viewed,
COUNT(TERMNAME) will store the details with
REPORT_API_USAGE reference. I need to create a report of views. Need to get
REPORT_API_USAGE for i in g:
print(i)
TERMID str = str.replace(/,#/g, '#');
面对面学习`视图计数以及相关事件和文档点击次数。
答案 0 :(得分:0)
表 report_api_usage 中有两行 termname ='面对面学习',因此返回两行。
您应该使用:
select ap.termname,
count(distinct ap.termname) as tot,
count(distinct ai.ctype) as event,
sum(case when ai.ctype = 'event' then 1 else 0 end) as page
from ...
我不明白你想要的数量..如果你想要计算多少 repoet_api_pages 有 ctype '事件'或'下载'使用以下查询:
select ap.termname,
count(ap.termname) as tot, -- if it total count rows in table report_api_usage, if you need unique count use distinct inside count function
sum(case when ai.ctype = 'download' then 1 else 0 end) as page_download
sum(case when ai.ctype = 'event' then 1 else 0 end) as page_event
from ...
答案 1 :(得分:0)
Finlay我找到了昂贵的查询。
SELECT AIP.TERMID,
(select count(RAU.TERMNAME) FROM REPORT_API_USAGE RAU WHERE RAU.TERMID = AIP.TERMID AND RAU.VOCID = 4) as page_views,
(select sum(count(RAU.TERMNAME)) FROM REPORT_API_USAGE RAU WHERE RAU.VOCID = 4
and RAU.TERMID in (select AIP.TERMID from REPORT_API_PAGES AIP GROUP BY AIP.TERMID) group by RAU.VOCID) as page_views_sum,
(select sum(count(AIP2.TERMID)) from REPORT_API_PAGES AIP2 join REPORT_API_USAGE RAU ON (RAU.TERMID = AIP2.TERMID AND RAU.VOCID = 4) where aip2.ctype = 'download' GROUP by AIP2.termid) as download_sum,
(select sum(count(AIP2.TERMID)) from REPORT_API_PAGES AIP2 join REPORT_API_USAGE RAU ON (RAU.TERMID = AIP2.TERMID AND RAU.VOCID = 4) where aip2.ctype = 'event' GROUP by AIP2.termid) as event_sum,
COUNT(case when aip.ctype = 'download' then 1 else null end) as page_download,
COUNT(case when aip.ctype = 'event' then 1 else null end) as page_event
from REPORT_API_PAGES AIP
GROUP BY AIP.TERMID