Skip to content

Instantly share code, notes, and snippets.

@bagofarms
Created August 30, 2017 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bagofarms/21ae9deb88853b4f165c0ec26ce2f31d to your computer and use it in GitHub Desktop.
Save bagofarms/21ae9deb88853b4f165c0ec26ce2f31d to your computer and use it in GitHub Desktop.
Here are some SQL statements I use to generate statistics about UDOIT usage.
/* Count the number of scans run per day */
SELECT COUNT(1) AS scans, DATE(date_run) as date
FROM reports
GROUP BY DATE(date_run)
/* Count the number of scans run by each user */
SELECT user_id, COUNT(1) AS scans
FROM reports
GROUP BY user_id
ORDER BY scans DESC
/* List all courses, sorted by number of errors, descending */
SELECT course_id, file_path, MAX(errors)
FROM reports
GROUP BY course_id
ORDER BY MAX(errors) DESC
/* Count the number of scans per course for a given time range */
SELECT course_id, COUNT(1) AS scans
FROM reports
WHERE date_run BETWEEN CAST('2015-07-01' AS DATE) AND CAST('2016-06-30' AS DATE)
GROUP BY course_id
ORDER BY scans DESC
/* Count the number of new users per day */
SELECT COUNT(1) AS users, DATE(date_created) as date
FROM users
GROUP BY DATE(date_created)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment