In the below query I need to include 2 more additional columns that calculates count of nativeprod(each of the 3 native prods - AAA, BBB, CCC) for each user id in last 1 day. I will change the where clause as NativeProd IN('AAA','BBB','CCC') and GlobalProd remains the same. Additionl column names below:
BBB_count_last_1_Day
CCC_count_last_1_Day
SELECT
userid,
nativeprodID,
nativeVersion,
nativeVersionName,
MAX(StartTime) AS Last_Used_TimeStamp,
SUM(IF(DATE(StartTime) > DATE(DATE_ADD(CURRENT_DATE() , -7, "DAY")), 1, 0)) AS count_last_7_days,
SUM(IF(DATE(StartTime) > DATE(DATE_ADD(CURRENT_DATE() , -15, "DAY")), 1, 0)) AS count_last_15_days,
SUM(IF(DATE(StartTime) > DATE(DATE_ADD(CURRENT_DATE() , -30, "DAY")), 1, 0)) AS count_last_30_days,
FROM [ProdTable]
WHERE NativeProd ='AAA' AND GlobalPod='AAA'
GROUP BY 1,2,3,4
LIMIT 10
I tried using partition by nativeprod but i got an error saying "missing function in analytic expression". My next option is to use join and match user ids to compute the values. Is there any other better way to handle this?