I'm a complete SQL Newbie andI need help with the following code:
SELECT DISTINCT userid , count( userid ) as login_count FROM ( SELECT DISTINCT userid , date( FROM_UNIXTIME( date_time ) ) AS DAY FROM xcart_login_history WHERE status="success" and (action ="login" or action = "autologin") ORDER BY userid, DAY ) as login_days WHERE login_days.DAY < ( SELECT DISTINCT min(date(FROM_UNIXTIME(xcart_orders.date))) FROM xcart_orders WHERE xcart_orders.userid = login_days.userid GROUP BY userid ) GROUP BY useriduserid; What it does: itThis shows me the loginsCOUNT of logins for individual users before purchasing (on. It is on purpose not returning more than one per day counted).
I now need the average login number / login count before purchase on a monthly basis. Meaning by that: The
For instance, the calculation should analyze the buys in January and from there on calculate the average logins (max 1 per day) that were necessary for this purchase.
Its driving me nuts...
Could please somebody help me? Thanks!