in below query need include 2 more additional columns calculates count of nativeprod(each of 3 native prods - aaa, bbb, ccc) each user id in last 1 day. change clause nativeprod in('aaa','bbb','ccc') , globalprod remains same. additionl column names below:
bbb_count_last_1_day
ccc_count_last_1_day
select
userid,
nativeprodid,
nativeversion,
nativeversionname,
max(starttime) last_used_timestamp,
sum(if(date(starttime) > date(date_add(current_date() , -7, "day")), 1, 0)) count_last_7_days,
sum(if(date(starttime) > date(date_add(current_date() , -15, "day")), 1, 0)) count_last_15_days,
sum(if(date(starttime) > date(date_add(current_date() , -30, "day")), 1, 0)) count_last_30_days,
[prodtable]
nativeprod ='aaa' , globalpod='aaa'
group 1,2,3,4
limit 10
i tried using partition nativeprod got error saying "missing function in analytic expression". next option use join , match user ids compute values. there other better way handle this?
select userid, nativeprodid, nativeversion, nativeversionname, max(starttime) last_used_timestamp, sum(if(date(starttime) > date(date_add(current_date() , -7, "day")), 1, 0)) count_last_7_days, sum(if(date(starttime) > date(date_add(current_date() , -15, "day")), 1, 0)) count_last_15_days, sum(if(date(starttime) > date(date_add(current_date() , -30, "day")), 1, 0)) count_last_30_days, -- new columns last 1 day sum(if(nativeprod = 'aaa' , date(starttime) > date(date_add(current_date() , -1, "day")), 1, 0)) aaa_count_last_1_day, sum(if(nativeprod = 'bbb' , date(starttime) > date(date_add(current_date() , -1, "day")), 1, 0)) bbb_count_last_1_day, sum(if(nativeprod = 'ccc' , date(starttime) > date(date_add(current_date() , -1, "day")), 1, 0)) ccc_count_last_1_day [prodtable] nativeprod in('aaa','bbb','ccc') , globalpod='aaa' group 1,2,3,4 limit 10
Comments
Post a Comment