0

I have to provide counts for different activities, some of the columns are from some table but few I have to take by joining other tables. And in the last column I have to add counts *of 5 columns togather in one field*.Please see my query below and advice the best way to achieve my results :)

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

I am really stuck as the table which is joined doesn'thave field named activity_count or activity_type so to see the counts I can only do count(*) but to add it all other fileds in one column and sum it up is very confusing??

Any help??/

4

1 回答 1

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;
于 2012-04-19T02:18:24.900 回答