[Answer]-Complex SQL syntax

1👍

I think I will use CTE though It has not been tested

WITH last_actions AS (
SELECT DISTINCT userId, MAX(aDate) as last_logged 
 FROM user_actions 
 GROUP BY userId ORDER BY userId)

SELECT a.userId, COUNT(b.pDate) 
 FROM last_actions a, prizes b 
 WHERE b.pDate >= a.last_logged      
 GROUP BY a.userId;

Leave a comment