我必须为不同的活动提供计数,有些列来自某些表,但很少我必须加入其他表。 在最后一栏中,我必须添加5个列的计数 * 以收集一个字段 *。请参阅下面的查询并建议实现结果的最佳方法:)
SELECT web. OID,web. MARKETING_GROUP,
SUM(DECODE(WEB.EVENT_TYPE,5,WEB.ACTIVITY_COUNT,0)) AS DISCUSSIONCOMMENT ,
SUM(DECODE(WEB.EVENT_TYPE,6,WEB.ACTIVITY_COUNT,0)) AS DISCUSSIONSTART ,
SUM(DECODE(WEB.EVENT_TYPE,7,WEB.ACTIVITY_COUNT,0)) AS DISCUSSIONVIEW,
SUM(case when o.when _clicked is not null then c(*))AS clickcount,
**SUM(case when WEB.EVENT_TYPE in(5,6,7,8)then WEB.ACTIVITY_COUNT +c.count(*))as Total** --------- This is where I am getting stuck and confused???
from GMMI_AIR.WEB_ACTIVITY_FCT WEB join GMMI_AIR.COUPON_WEB_ACTIVITY C
on WEB.OID_WEB_ACTIVITY_FCT = C.OID_COUPON_WEB_ACTIVITY
我真的被卡住了,因为加入的表没有名为activity_count或activity_type的字段,所以要查看我只能计数的计数(*),但要将所有其他文件添加到一列中并总结它是非常的混乱??
任何帮助?? /
答案 0 :(得分:1)
SELECT web. OID,web. MARKETING_GROUP,
SUM(DECODE(WEB.EVENT_TYPE,5,WEB.ACTIVITY_COUNT,0)) AS DISCUSSIONCOMMENT ,
SUM(DECODE(WEB.EVENT_TYPE,6,WEB.ACTIVITY_COUNT,0)) AS DISCUSSIONSTART ,
SUM(DECODE(WEB.EVENT_TYPE,7,WEB.ACTIVITY_COUNT,0)) AS DISCUSSIONVIEW,
SUM(case when o.when _clicked is not null then c(*))AS clickcount,
SUM(case when WEB.EVENT_TYPE in(5,6,7,8)then WEB.ACTIVITY_COUNT END) +c.count(*) as Total
from GMMI_AIR.WEB_ACTIVITY_FCT WEB join GMMI_AIR.COUPON_WEB_ACTIVITY C
on WEB.OID_WEB_ACTIVITY_FCT = C.OID_COUPON_WEB_ACTIVITY
GROUP BY web. OID,web. MARKETING_GROUP;