Sample queries

In this section, we provide several sample SQL queries to answer typical reporting needs like:

Additionally, in the following section, we provide SQL queries that replicate key reports in the Groups tab.

Users who have gained XP in the last 7 days

To track which users actively engage with the platform, you can use XP as a proxy for activity and look at users who have recently earned XP.

The following query returns a list of all users that earned XP in the last 7 days.

SELECT
  user.email,
  max(events.occurred_at) AS last_xp_at
FROM data_connector_1234.fact_learn_events AS events
LEFT JOIN data_connector_1234.dim_user AS user 
  ON events.user_id = user.user_id
WHERE events.event_name IN ('assessment_engaged', 
                    'course_engagement', 
                    'practice_engagement', 
                    'project_engagement', 
                    'b2b_onboarding_xp_boost', 
                    'alpa_onboarding')
  AND date(events.occurred_at) >= date_add('day', -7, current_date)
  AND events.xp_earned > 0
GROUP BY user.email
ORDER BY last_xp_at DESC

You can also use the query above to identify your top learners for an XP competition. Simply modify the date filter to include the competition period.

All current members of the group

Another common request is a list of the organization's users. The query below returns a list of all current members in your group and their start date.

Removed users

Please notice the bug.ended_at filter. If you leave this out, the query will also return the users who have been in your group but have since been removed. You can then include bug.ended_at in the SELECT clause to get the date a user left the group.

Time spent in Learn per technology

Each content type at DataCamp has an associated technology (e.g., R, Python, SQL, Spark, etc.). If you want to examine what technologies your users are most focused on, you can create a report with the time spent per technology with the query below.

You can include a restriction in the WHERE clause if you would like to limit the results to a particular period.

Time spent in Learn per team

If you want to see how different teams in your organization are taking advantage of our platform, we can modify the query above to look at the time spent per team in Learn content (assessments, courses, practices, and projects).

On team membership and scope

  • Keep in mind that the query above only shows XP gained by the users currently in the respective team; this means that once someone leaves a team, the team's XP calculation would decrease.

  • A single user can be a member of multiple teams, which means their XP is included in each team's total. Adding up these team-XP values will not match the total XP gained across all users.

If you would like time_spent to remain allocated to the team even if a user has left the team, you can use the bridge_user_team table which has started_at and ended_at columns to calculate the period the user was part of a team.

You can include a restriction in the WHERE clause of the bottom section if you want to limit the results to a particular period.

Time spent in Learn per user

You may be interested in reviewing the time each of your organization's users has spent learning on our platform. The following query returns each user's time spent in Learn content (assessments, courses, practices, and projects).

DataLab, Certification, and other products are not included in the query above.

You can include a restriction in the WHERE clause if you would like to limit the results to a particular period.

XP earned by user

A different way to look at engagement is to measure XP. You can track how active each of your organization's users has been on our platform with the query below that displays the total XP per user.

You can include a restriction in the WHERE clause if you would like to limit the results to a particular period.

Completed courses by user

It is often necessary to review learning activity on a more granular level. A common question is, "What courses have our users completed?" The query below returns all courses completed by users in your organization.

You can include a restriction in the WHERE clause if you would like to limit the results to a particular period.

Completed assessments by user

Testing a user's skill level is an integral part of learning. If you want a report of all the assessments your organization's users have completed, the query below will tell you all complete assessments and their user, score, percentile, and completion date.

You can include a restriction in the WHERE clause if you would like to limit the results to a particular period.

Last updated