Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
SQL Inactive Active Subscribers
00:00
5 left

SQL Inactive Active Subscribers

MediumSQL · PostgreSQL

Problem

Write a SQL query to find all users who have active subscriptions but have not logged into the app in the last 30 days at Truebill.

Use the provided users, subscriptions, and app_logins tables. Treat subscriptions with status active and no past end date as active.

Output

  1. Return one row per qualifying user.
  2. Include user_id, email, and last_login_at.
  3. Include users with no login history, exclude users with a login during the last 30 days, and sort by user_id ascending.

Schema

users
ColumnTypeDescription
user_idPKINTUnique Truebill user identifier
emailVARCHAR(255)User email address
subscriptions
ColumnTypeDescription
subscription_idPKINTUnique subscription identifier
user_idINTUser who owns the subscription
statusVARCHAR(20)Current subscription status
end_dateDATESubscription end date, or NULL for an open-ended subscription
app_logins
ColumnTypeDescription
login_idPKINTUnique login event identifier
user_idINTUser who logged into the app
login_atTIMESTAMPTimestamp of the login event
Tablesuserssubscriptionsapp_logins
Interviewer

Your question is SQL Inactive Active Subscribers. Start with the requirements and the three tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.