SELECT  B.speaker_id, S.name AS mentor, V.course_id, C.name AS curso,  V.lesson_id, L.name AS leccion, V.created_at,
COUNT(*) AS vistas
FROM speakers AS S
INNER JOIN speakeables AS B
ON S.id = B.speaker_id
inner join courses AS C
on B.speakeable_id = C.id
AND B.speakeable_type LIKE '%Course%'
inner join lessons AS L 
ON C.id = L.course_id
inner join views AS V
ON L.id = V.lesson_id
AND  V.course_paid=1 
AND  V.lesson_paid=1 
WHERE S.user_id <> V.user_id
AND (V.created_at BETWEEN date_format(DATE_SUB(CURDATE(), interval 1 WEEK),'%Y-%m-%d %H:%i:%s') 
	AND  date_format(date_add(CURDATE(),interval 1 DAY),'%Y-%m-%d %H:%i:%s') )
GROUP BY B.speaker_id, V.course_id, V.lesson_id
ORDER BY mentor, curso, leccion;  

select date_format(DATE_SUB(CURDATE(), interval 1 WEEK),'%Y-%m-%d %H:%i:%s') , date_format(date_add(CURDATE(),interval 1 DAY),'%Y-%m-%d %H:%i:%s');



SELECT * FROM views AS V 
WHERE  -- V.course_paid=1 
-- AND  V.lesson_paid=1 
-- AND 
(V.created_at BETWEEN date_format(DATE_SUB(CURDATE(), interval 1 WEEK),'%Y-%m-%d %H:%i:%s') 
AND  date_format(date_add(CURDATE(),interval 1 DAY),'%Y-%m-%d %H:%i:%s') )
ORDER BY lesson_id;

SELECT * FROM speakeables AS B 
WHERE B.speakeable_id = 319 
AND B.speakeable_type REGEXP 'Course';