Search Posts

Author: user9651591

Translate Lead/Lag function to MySQL

how to – Translate Lead/Lag function to MySQL How do I translated the below codes so that it runs in MySQL. I am new to MySQL and finding it difficult to understand few things. CODE 1: SELECT t1.user_id, t1.visit_month LEAD (t1.visit_month, 1) OVER (partition BY t1.user_id ORDER BY t1.user_id, t1.visit_month) FROM (SELECT user_id, month(date_time) as visit_month FROM tbl_activity group by 1, 2 ORDER BY 1 , 2) t1; CODE 2: SELECT user_id, visit_month, lead, lead […]

mySQL – Date Difference and Flags

how to – mySQL – Date Difference and Flags I am very new to mySQL and currently working on a table with three columns: trx_id, user_id, last_activity. (Churn Analysis) tbl_activity: The table capture activity of users. I am finding it difficulty in performing two tasks. 1) I would like to see two new columns through SQL query date difference between subsequent transactions. flag based on condition > 30 days. desired table: 2) One of the […]