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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free
Filter Authorized Sensitive Dataset Grants
00:00
5 left

Filter Authorized Sensitive Dataset Grants

HardSQL · PostgreSQL

Problem

How would you handle permissions and security on sensitive data sets?

Translate the access policy into a PostgreSQL query that returns only currently authorized dataset grants. Sensitive datasets require an active user, enabled MFA, and an approved security role. Standard datasets require only an active user and a valid grant.

Output

  1. One row per authorized grant
  2. Columns: email, dataset_name, classification, permission_level, granted_role, and access_scope
  3. Exclude inactive users, inactive datasets, revoked grants, expired grants, and unauthorized sensitive access
  4. Order by email, then dataset_name

Output details

  • Treat DATE '2026-01-15' as today's date.
  • Treat public and internal classifications as standard, and restricted and secret classifications as sensitive.
  • Require sensitive access to users whose role is security_admin or data_protection, with mfa_enabled true.
  • Treat grants with revoked_at NULL and expires_at NULL or on/after DATE '2026-01-15' as valid.
  • Derive access_scope as sensitive for restricted or secret, otherwise standard.
  • Sort email and then dataset_name in ascending order without an additional tie-breaker.

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
emailVARCHAR(255)User email address
roleVARCHAR(50)User security role
is_activeBOOLEANWhether the user account is active
mfa_enabledBOOLEANWhether multi-factor authentication is enabled
datasets
ColumnTypeDescription
dataset_idPKINTUnique dataset identifier
dataset_nameVARCHAR(150)Dataset name
classificationVARCHAR(30)Data classification such as public, internal, restricted, or secret
owner_teamVARCHAR(100)Team responsible for the dataset
is_activeBOOLEANWhether the dataset is available
access_grants
ColumnTypeDescription
grant_idPKINTUnique grant identifier
user_idINTUser receiving the grant
dataset_idINTDataset covered by the grant
permission_levelVARCHAR(30)Granted access level
granted_roleVARCHAR(50)Role recorded when access was granted
revoked_atDATEDate the grant was revoked
expires_atDATEGrant expiration date
Tablesusersdatasetsaccess_grants
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the three tables are in the Question tab.

Sign up free to run or submit. Log in
CodePostgreSQL
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 1
Run your query to see results here.