How to count number of distinct days from one table using two dates (for range) from another table for each row?
SELECT a.*, COUNT(DISTINCT b.loginday)
FROM usertable a
JOIN logintable b 
    ON b.loginday BETWEEN a.mindate AND a.maxdate
GROUP BY a.userid /* , a.mindate, a.maxdate, ... */