← SQL workplace practice

Access and evidence policies · Original fictional data · Free files and full answers

Explain which inherited principal supplies access evidence

For requests list each applicable nonpublic allow grant whose principal is not the requesting user, including transitive groups. Return request_id,grant_id,principal sorted request_id,grant_id.

Use this fixed business case to build a checked CSV and a replayable SQL handoff. No account required. Scenario datasets are shared across related exercises; each exercise has its own decision and output contract.

Your output contract

  1. For requests list each applicable nonpublic allow grant whose principal is not the requesting user, including transitive groups. Return request_id,grant_id,principal sorted request_id,grant_id.
  2. Return exactly the declared columns and order. Money uses integer cents; time and date units follow the task and field dictionary. NULL is unknown and differs from numeric zero.
  3. These are original fictional records and exercise policies. Scenario data may be shared with related tasks, whose decisions and output contracts differ.

Return columns exactly as request_id, grant_id, principal. Sort order follows the task. Output has 5 rows; an empty CSV field means NULL.

Source data

grants

10 source rows · Download grants CSV

id INTEGERprincipal TEXTresource TEXTeffect TEXTexpires INTEGERmask INTEGER
1alicedocsallow201
2teamdocsallow502
3alicesecretdeny503
4teamsecretallow501
5bobdocsallow50
6reviewerfinanceallow502
7publicopenallow500
8teamoldallow81
9alicefinanceallow501
10alicearchiveallow501

members

3 source rows · Download members CSV

member TEXTparent TEXT
aliceteam
bobteam
teamreviewer

requests

8 source rows · Download requests CSV

id INTEGERuser TEXTresource TEXTday INTEGER
1alicedocs10
2alicesecret10
3bobdocs10
4bobfinance10
5aliceold10
6outsideropen10
7outsiderdocs10
8alicefinance10

approvals

4 source rows · Download approvals CSV

id INTEGERrequester TEXTapprover TEXTresource TEXT
1alicealicefinance
2alicebobfinance
3boboutsiderdocs
4bobalicesecret
Field dictionary and schema
grants:
  id INTEGER — Stable source record identifier; not a row position.
  principal TEXT — Literal business key or category label. Match exactly and retain NULL where present.
  resource TEXT — Literal business key or category label. Match exactly and retain NULL where present.
  effect TEXT — Permission outcome, allow or deny.
  expires INTEGER — Expiry boundary; the goal declares whether equality is eligible.
  mask INTEGER — Privacy mask level; higher values require stricter masking.

members:
  member TEXT — Literal business key or category label. Match exactly and retain NULL where present.
  parent TEXT — Immediate parent identifier, or NULL for a hierarchy root.

requests:
  id INTEGER — Stable source record identifier; not a row position.
  user TEXT — Literal business key or category label. Match exactly and retain NULL where present.
  resource TEXT — Literal business key or category label. Match exactly and retain NULL where present.
  day INTEGER — Integer day index, or ISO YYYY-MM-DD date when stored as text; the task declares cutoff semantics.

approvals:
  id INTEGER — Stable source record identifier; not a row position.
  requester TEXT — Literal business key or category label. Match exactly and retain NULL where present.
  approver TEXT — Literal business key or category label. Match exactly and retain NULL where present.
  resource TEXT — Literal business key or category label. Match exactly and retain NULL where present.

Download complete SQLite setup

A method you can reuse

  1. For requests list each applicable nonpublic allow grant whose principal is not the requesting user, including transitive groups. Return request_id,grant_id,principal sorted request_id,grant_id.
  2. For the first output record, request_id = 1; grant_id = 2; principal = team.
  3. Inspect the source grain, keys and ties. Compare each result column with the full worked SQL and expected CSV.

Watch for this wrong turn

A closure list alone lacks the resource, expiry and grant identity required to explain a permission.

Run and check in SQLite

Your SQL runs locally in the existing SQLite worker. The checker compares every column, row, type, value and row order with this fixed output. It accepts equivalent SELECT or WITH queries. Browser storage keeps your SQL on this device when available.

Complete worked SQL and expected output
WITH RECURSIVE m(user,principal) AS (SELECT user,user FROM requests UNION SELECT m.user,g.parent FROM m JOIN members g ON g.member=m.principal) SELECT DISTINCT r.id request_id,g.id grant_id,g.principal FROM requests r JOIN m ON m.user=r.user JOIN grants g ON g.principal=m.principal AND g.resource=r.resource AND g.expires>r.day AND g.effect='allow' WHERE g.principal<>r.user ORDER BY r.id,g.id;
"request_id","grant_id","principal"
"1","2","team"
"2","4","team"
"3","2","team"
"4","6","reviewer"
"8","6","reviewer"
Reference SQL · Complete expected CSV · Empty answer CSV

Choose another SQL task · Original data exception cases · Larger workplace projects