I am having difficulties running a custom query. The query works on my servers as well as different mysql clients but I am not sure why it isn't here.
The query:
SELECT t.month, t.year, SUM(CASE WHEN status = 'Churned' THEN 1 ELSE 0 END) as 'churned_no', SUM(CASE WHEN status = 'Active' THEN 1 ELSE 0 END) as 'active_no', SUM(CASE WHEN status = 'Resurrected' THEN 1 ELSE 0 END) as 'resurrected_no', SUM(cASE WHEN status = 'Inactive' THEN 1 ELSE 0 END) as 'inactive_no' FROM ( SELECT t1.user_id, t1.month month, t1.year year, t2.month pmonth, t2.year pyear, t1.count>20 cmonth_active, t2.count>20 pmonth_active, CASE WHEN t1.count>20 = 0 and t2.count>20 = 1 THEN 'Churned' WHEN t1.count>20 = 1 and t2.count>20 = 1 THEN 'Active' WHEN t1.count>20 = 1 and t2.count>20 = 0 THEN 'Resurrected' WHEN t1.count>20 = 0 and t2.count>20 = 0 THEN 'Inactive' ELSE 'ERROR' END as status FROM ( SELECT tmp2.month, tmp2.date, tmp2.user_id, tmp2.year, tmp2.activity_type, sum(tmp2.count) count FROM triggers tmp2 WHERE (tmp2.date BETWEEN '2013-01-01' and '2015-12-31') GROUP BY tmp2.year, tmp2.month, tmp2.user_id ) t1 inner JOIN ( SELECT tmp1.month, tmp1.user_id, tmp1.year,tmp1.activity_type, sum(tmp1.count) count FROM triggers tmp1 WHERE (tmp1.date BETWEEN DATE_SUB(STR_TO_DATE('2013-01-01', '%Y-%m-%d'), INTERVAL 1 MONTH) and '2015-12-31') -- and t2.activity_type = 'login' -- (tmp1.date BETWEEN '2013-01-01' and '2013-12-31') GROUP BY tmp1.year, tmp1.month, tmp1.user_id ) t2 ON t1.activity_type = t2.activity_type and (t1.user_id = t2.user_id) and YEAR(DATE_SUB(t1.date, INTERVAL 1 MONTH)) = t2.year and MONTH(DATE_SUB(t1.date, INTERVAL 1 MONTH)) = t2.month ) t GROUP BY t.year, t.month
The error:
Error Details:
Parsing of SQL query failed. Please check the SQL syntax.
Some tips:
Parse error at line 9, column 34. Encountered: =