Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FILTER_STARTTIME and FILTER_ENDTIME on different fields #205

Open
martosource opened this issue Feb 7, 2022 · 0 comments
Open

FILTER_STARTTIME and FILTER_ENDTIME on different fields #205

martosource opened this issue Feb 7, 2022 · 0 comments

Comments

@martosource
Copy link

I'm trying to create a custom sql report the start and end filter. I would like to apply the filter to both timeenrolled and timecompleted in different subqueries.

The filter for the timecompleted is not being applied.

Source SQL:

SELECT fullname as Course, Enrolments.Total as Enrolments, CompletedEnrolments.Total as Completed
FROM prefix_course c
LEFT OUTER JOIN 
(SELECT course, COUNT(*) AS Total
FROM prefix_course_completions cc
JOIN  prefix_user_info_data d ON cc.userid = d.userid
WHERE d.fieldid = 2 %%FILTER_USERS:d.data%%  
%%FILTER_STARTTIME:cc.timeenrolled:>=%% %%FILTER_ENDTIME:cc.timeenrolled:<=%% 
GROUP BY course) AS Enrolments ON c.id = Enrolments.course

LEFT OUTER JOIN (SELECT course, COUNT(*) AS Total
FROM prefix_course_completions cc2
JOIN  prefix_user_info_data d ON cc.userid = d.userid
WHERE d.fieldid = 2 %%FILTER_USERS:d.data%%  
%%FILTER_STARTTIME:cc2.timecompleted:>=%% %%FILTER_ENDTIME:cc2.timecompleted:<=%% 
GROUP BY course) 
AS CompletedEnrolments ON c.Id = CompletedEnrolments.course

WHERE Enrolments.Total > 0 OR CompletedEnrolments.Total > 0

Generated sql

SELECT fullname as Course, Enrolments.Total as Enrolments, CompletedEnrolments.Total as Completed
FROM mood_course c
LEFT OUTER JOIN 
(SELECT course, COUNT(*) AS Total
FROM mood_course_completions cc
JOIN  mood_user_info_data d ON cc.userid = d.userid
WHERE d.fieldid = 2  AND d.data LIKE '%NSW%'  
 AND cc.timeenrolled >= 1640998920  AND cc.timeenrolled <= 1644282120 
GROUP BY course) AS Enrolments ON c.id = Enrolments.course

LEFT OUTER JOIN (SELECT course, COUNT(*) AS Total
FROM mood_course_completions cc2
JOIN  mood_user_info_data d ON cc2.userid = d.userid
WHERE d.fieldid = 2  AND d.data LIKE '%NSW%'  
  
GROUP BY course) 
AS CompletedEnrolments ON c.Id = CompletedEnrolments.course

WHERE Enrolments.Total > 0 OR CompletedEnrolments.Total > 0 LIMIT 0, 5000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant