Skip to content

Instantly share code, notes, and snippets.

@rocaiguina
Last active July 29, 2020 18:38
Show Gist options
  • Save rocaiguina/99721ecc8681133f2fb6673101caee5d to your computer and use it in GitHub Desktop.
Save rocaiguina/99721ecc8681133f2fb6673101caee5d to your computer and use it in GitHub Desktop.
SELECT user_group,
fname,
lname,
email,
module,
total_activities,
case
total_activities
when 1 then 'video only'
when 3 then 'video and practice'
when 4 then 'video and assessment'
when 6 then 'all taken'
end as 'taken activities',
if(total_activities > 3, 'complete', 'incomplete') act_status,
start_date,
end_date
FROM(
SELECT user_group,
fname,
lname,
email,
module,
sum(activity_id) as total_activities,
min(activity_date) start_date,
max(activity_date) end_date
FROM (
SELECT users_view.user_group,
users_view.fname,
users_view.lname,
users_view.email,
wp_posts.post_title module,
wp_a_learn_activity.activity_description component,
wp_a_learn_activity.activity_id,
wp_a_learn_progress_log.activity_date
from users_view
INNER JOIN wp_a_learn_progress_log ON users_view.user_id = wp_a_learn_progress_log.user_id
INNER JOIN wp_posts ON wp_posts.ID = wp_a_learn_progress_log.post_id
INNER JOIN wp_a_learn_activity ON wp_a_learn_activity.activity_id = wp_a_learn_progress_log.activity_id
GROUP BY users_view.user_id,
wp_posts.ID,
wp_a_learn_activity.activity_description
) as users_modules
group by email,
module
) as um2
WHERE (
(user_group LIKE 'Wordpress') || ($ P { userGroup } IS NULL) || ($ P { userGroup } = ' ')
)
AND (
(module LIKE 'trainingModule') || ($ P { trainingModule } IS NULL) || ($ P { trainingModule } = ' ')
)
AND (
($ P { completionStatus } IS NULL) || ($ P { completionStatus } = ' ') || (
$ P { completionStatus } = 'complete'
AND (total_activities > 3)
) || (
$ P { completionStatus } = 'incomplete'
AND total_activities <= 3
)
)
ORDER BY user_group
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment