DB Olympics

Queries · q328 · Data Protection Officer · week 2, night 2

Evidence check on the 3 legal-hold-linked chargeback disputes

“For the 3 accounts under a payment-dispute legal hold, what internal evidence (payment status, support ticket activity) suggests whether the underlying dispute is still active or has gone stale?”

Manager · asked the questionInes LaurentData Protection Officer. Lawyer by training, previously at a European marketplace. Also reports to the board's audit committee.
Analyst · planned the reportPriyanka DesaiAuditor's mindset: traces individual records end to end to check that the totals are real.
Engineer · wrote the SQLInesThinks in window functions: ranks, running totals, LAG/LEAD for comparisons, percent-of-total.

Fictional people at a fictional company, each played by a language-model agent. Who they are and what they are told

  1. A business event lands on the Data Protection Officer's desk

    Week 2; shared with Henrik Aalto, Chief Information Security Officer

    A data protection authority asked how we handle privacy: how many privacy requests we receive and how fast we complete them, how consent is recorded, and what remains after an account is deleted.

  2. Ines Laurent writes to Priyanka Desai

    The manager, at the start of week 2

    Subject: Week 2 — DPA inquiry changes our priorities

    Priyanka,

    Good work — this is exactly the kind of digging I wanted. A few things surprised me and now matter more because of the regulator inquiry (which I'm handling jointly with Henrik Aalto, CISO — our response needs to be accurate and defensible, not just reassuring).

    What struck me:

    • The three "open" erasure requests aren't really open, they're parked behind legal holds — but we don't actually know if those holds are still justified. If a regulator asked us today why those erasures haven't happened, "disputes" that are 1.5–2.6 years old is not a comfortable answer without evidence.
    • We have a closure-tracking gap (rejected requests never get a completion date) and apparently zero portability requests in three years. Both could be true, or both could be an artifact of how we log things — and I don't want to hand the regulator a number I can't stand behind.
    • The email retention failure is concrete and fixable, but it also means I can't yet answer "what remains after an account is deleted" with confidence for other categories until we know how widespread this is.
    • The consent anomaly (one category showing suspiciously perfect opt-in) undermines my confidence in saying "this is how consent is recorded" to a regulator until it's explained.

    So, for this week, please prioritize work that lets us answer the DPA's three questions honestly: volume and speed of privacy requests, how consent is captured and whether it's reliable, and what data persists post-deletion. That's the deliverable Henrik and I need to brief the board audit committee before we respond.

    My questions:

    1. For the three long-running legal holds, can we establish — from whatever evidence exists — whether the underlying disputes are still active, so I can decide whether to push for release or document why they must stand?
    2. Can we get a trustworthy, defensible count of privacy requests received and resolved, including the rejected ones and whether "zero portability requests ever" is real or a logging blind spot — the regulator will ask for exactly this?
    3. How confident can we be in what consent records actually show, given the anomaly you flagged — do we have other categories with the same too-clean pattern, and does that change how I'd describe our consent process to a regulator?
    4. Beyond email, how much shopper data elsewhere is sitting past its stated retention window right now — I need a true current picture of "what remains after deletion," not just the one confirmed violation.

    If all four can't fit, start with 2 and 4 — those go directly into the regulator response.

    Thanks, Ines

    A note from the Chief Information Security Officer, Henrik Aalto

    Subject: Security angle for the DPA response

    Hi Priyanka,

    A few things from my side that would strengthen the privacy response:

    1. When a data subject request results in erasure, can we show what login/session and access history remains afterward, and for how long — i.e. do our retention rules actually clear it out, or does it linger?
    2. For consent withdrawals, do we have any evidence that we stop using/collecting the related data promptly (e.g. no further sign-ins or sensitive-data access tied to that account after withdrawal)?
    3. On the completion-time question the DPA is asking about — can we also show whether requests touching account security data (sessions, API/service credentials, access logs) take longer to close than others? That's often where delays hide.

    Happy to compare notes before you send anything to data engineering.

    Henrik

  3. Priyanka Desai plans the night

    The analyst · week 2, night 2, request 3 of 3

    Two things from last night need resolving before I trust the numbers for the regulator: (1) report 1 showed DSAR received_at dates as early as 2020-04-24 and 2022-08-25 — before the stated 2023-01-01 warehouse history start — which could be legitimate backfilled compliance records carried over from the pre-migration system, or could be a data quality artifact; I need to see these specific rows and compare received_at to created_at to tell which. (2) report 2 showed all 11 data_exports linked to a DSAR, but completed_export_count was 0, and the engineer flagged uncertainty about whether 'completed' is even the right status string for that table — if genuinely zero exports ever finished, that's a real fulfillment failure (shoppers who filed access requests may never have actually received their data), separate from the "portability doesn't exist as a request_type" question I already closed. Both are quick, cheap diagnostics. With priorities 2 and 4 now largely resolved (volumes reconcile to 60 pending the pre-2023 check; retention is fine everywhere except email_log, confirmed last night), I'm using my third slot to start priority 1 for Ines: looking for whatever internal evidence exists (payment status, support ticket activity) on the 3 held accounts, since there's no explicit "dispute" table and the legal holds aren't linked to a specific order/payment — I have to reconstruct it from the subject_user_id.

    Evidence check on the 3 legal-hold-linked chargeback disputes
    Question
    For the 3 accounts under a payment-dispute legal hold, what internal evidence (payment status, support ticket activity) suggests whether the underlying dispute is still active or has gone stale?
    One row per
    legal hold (3 rows: Marrowby & Vane, Rue Lafayette Studio, Cragsley Outfitters)
    Columns
    • tenant name
    • subject_user_id
    • hold placed_at (date)
    • days since placed (2026-01-05 minus placed_at)
    • latest payment status for this user (most recent by updated_at, via orders.user_id = subject_user_id joined to payments)
    • latest payment updated_at (date)
    • latest payment amount and currency
    • open ticket count for this user (tickets.requester_user_id, status not in solved/closed)
    • most recent ticket last_message_at for this user (date)
    • days since that last ticket activity
  4. Ines writes the SQL

    The engineer · 1 dry run on the empty schema, then the submission

    Dry run 1 · STATUS: COMPILES (dry run on the empty schema, no data read)
    WITH holds AS (
      SELECT lh.id AS legal_hold_id, lh.tenant_id, lh.subject_user_id, lh.placed_at, t.name AS tenant_name
      FROM legal_holds lh
      JOIN tenants t ON t.id = lh.tenant_id
      WHERE lh.is_active = true
        AND t.name IN ('Marrowby & Vane', 'Rue Lafayette Studio', 'Cragsley Outfitters')
    ),
    latest_payment AS (
      SELECT h.legal_hold_id, p.status, p.updated_at, p.amount, p.currency_code,
             ROW_NUMBER() OVER (PARTITION BY h.legal_hold_id ORDER BY p.updated_at DESC) AS rn
      FROM holds h
      JOIN orders o ON o.user_id = h.subject_user_id AND o.tenant_id = h.tenant_id
      JOIN payments p ON p.order_id = o.id
    ),
    latest_payment_top AS (
      SELECT * FROM latest_payment WHERE rn = 1
    ),
    open_tickets AS (
      SELECT h.legal_hold_id, COUNT(*) AS open_ticket_count
      FROM holds h
      JOIN tickets tk ON tk.requester_user_id = h.subject_user_id AND tk.tenant_id = h.tenant_id
      WHERE tk.status NOT IN ('solved','closed')
      GROUP BY h.legal_hold_id
    ),
    latest_ticket AS (
      SELECT h.legal_hold_id, tk.last_message_at,
             ROW_NUMBER() OVER (PARTITION BY h.legal_hold_id ORDER BY tk.last_message_at DESC) AS rn
      FROM holds h
      JOIN tickets tk ON tk.requester_user_id = h.subject_user_id AND tk.tenant_id = h.tenant_id
    ),
    latest_ticket_top AS (
      SELECT * FROM latest_ticket WHERE rn = 1
    )
    SELECT
      h.tenant_name,
      h.subject_user_id,
      CAST(h.placed_at AS date) AS hold_placed_date,
      DATE '2026-01-05' - CAST(h.placed_at AS date) AS days_since_placed,
      lp.status AS latest_payment_status,
      CAST(lp.updated_at AS date) AS latest_payment_updated_date,
      lp.amount AS latest_payment_amount,
      lp.currency_code AS latest_payment_currency,
      COALESCE(ot.open_ticket_count, 0) AS open_ticket_count,
      CAST(lt.last_message_at AS date) AS latest_ticket_activity_date,
      DATE '2026-01-05' - CAST(lt.last_message_at AS date) AS days_since_ticket_activity
    FROM holds h
    LEFT JOIN latest_payment_top lp ON lp.legal_hold_id = h.legal_hold_id
    LEFT JOIN open_tickets ot ON ot.legal_hold_id = h.legal_hold_id
    LEFT JOIN latest_ticket_top lt ON lt.legal_hold_id = h.legal_hold_id
    ORDER BY days_since_placed DESC, h.tenant_name

    “Query compiles with the expected 11 columns at the requested grain. Submitting.”

    Submitted · the SQL of the last dry run, unchanged · Submitted to tonight's batch. Your work on this request is done.

    “Submitted. The report joins the 3 payment-dispute legal holds (Marrowby & Vane, Rue Lafayette Studio, Cragsley Outfitters) to each subject user's most recent payment and ticket activity as indirect evidence of dispute freshness, ordered by days since the hold was placed (most stale first). Note: since legal_holds doesn't link to a specific payment/ticket for these rows, this is an approximation using the user's overall latest activity, as I flagged in the submit note.”

  5. The report comes back overnight

    As Priyanka Desai saw it, from the small dataset the agents worked on

    tenant_name          | subject_user_id | hold_placed_date | days_since_placed | latest_payment_status | latest_payment_updated_date | latest_payment_amount | latest_payment_currency | open_ticket_count | latest_ticket_activity_date | days_since_ticket_activity
    ---------------------+-----------------+------------------+-------------------+-----------------------+-----------------------------+-----------------------+-------------------------+-------------------+-----------------------------+---------------------------
    Marrowby & Vane      |            1933 | 2023-05-27       |               954 | partially_refunded    | 2025-03-11                  |              530.9000 | GBP                     |                 0 |                        NULL |                       NULL
    Rue Lafayette Studio |            5911 | 2024-07-10       |               544 | captured              | 2024-12-05                  |               86.9900 | EUR                     |                 0 |                        NULL |                       NULL
    Cragsley Outfitters  |            6446 | 2025-03-22       |               289 | partially_refunded    | 2025-07-08                  |               90.9100 | USD                     |                 0 |                        NULL |                       NULL
    (3 rows)
  6. What came of it

    The memo and the queries that followed; links found by title, so inferred

    It builds on:

  7. It becomes benchmark query q328

    Changed only where the benchmark needs the same result on every system

    • determinismtie-breaker in row_number: payments.id
    • determinismtie-breaker: legal_hold_id is the row key
    • made explicita selected t.col gets AS col, its standard name made explicit (13×)
    • determinismthe standard leaves the place of NULLs in a sort to the implementation: NULLS LAST ascending, NULLS FIRST descending, as in the reference results (6×)
    The benchmark text, against the submitted SQL
    WITH holds AS (  SELECT lh.id AS legal_hold_id, lh.tenant_id, lh.subject_user_id, lh.placed_at, t.name AS tenant_name  SELECT lh.id AS legal_hold_id, lh.tenant_id AS tenant_id, lh.subject_user_id AS subject_user_id, lh.placed_at AS placed_at, t.name AS tenant_name  FROM legal_holds lh  JOIN tenants t ON t.id = lh.tenant_id  WHERE lh.is_active = true    AND t.name IN ('Marrowby & Vane', 'Rue Lafayette Studio', 'Cragsley Outfitters')),latest_payment AS (  SELECT h.legal_hold_id, p.status, p.updated_at, p.amount, p.currency_code,         ROW_NUMBER() OVER (PARTITION BY h.legal_hold_id ORDER BY p.updated_at DESC) AS rn  SELECT h.legal_hold_id AS legal_hold_id, p.status AS status, p.updated_at AS updated_at, p.amount AS amount, p.currency_code AS currency_code,         ROW_NUMBER() OVER (PARTITION BY h.legal_hold_id ORDER BY p.updated_at DESC NULLS FIRST, p.id DESC NULLS FIRST) AS rn  FROM holds h  JOIN orders o ON o.user_id = h.subject_user_id AND o.tenant_id = h.tenant_id  JOIN payments p ON p.order_id = o.id),latest_payment_top AS (  SELECT * FROM latest_payment WHERE rn = 1),open_tickets AS (  SELECT h.legal_hold_id, COUNT(*) AS open_ticket_count  SELECT h.legal_hold_id AS legal_hold_id, COUNT(*) AS open_ticket_count  FROM holds h  JOIN tickets tk ON tk.requester_user_id = h.subject_user_id AND tk.tenant_id = h.tenant_id  WHERE tk.status NOT IN ('solved','closed')  GROUP BY h.legal_hold_id),latest_ticket AS (  SELECT h.legal_hold_id, tk.last_message_at,         ROW_NUMBER() OVER (PARTITION BY h.legal_hold_id ORDER BY tk.last_message_at DESC) AS rn  SELECT h.legal_hold_id AS legal_hold_id, tk.last_message_at AS last_message_at,         ROW_NUMBER() OVER (PARTITION BY h.legal_hold_id ORDER BY tk.last_message_at DESC NULLS FIRST) AS rn  FROM holds h  JOIN tickets tk ON tk.requester_user_id = h.subject_user_id AND tk.tenant_id = h.tenant_id),latest_ticket_top AS (  SELECT * FROM latest_ticket WHERE rn = 1)SELECT  h.tenant_name,  h.subject_user_id,  h.tenant_name AS tenant_name,  h.subject_user_id AS subject_user_id,  CAST(h.placed_at AS date) AS hold_placed_date,  DATE '2026-01-05' - CAST(h.placed_at AS date) AS days_since_placed,  lp.status AS latest_payment_status,  CAST(lp.updated_at AS date) AS latest_payment_updated_date,  lp.amount AS latest_payment_amount,  lp.currency_code AS latest_payment_currency,  COALESCE(ot.open_ticket_count, 0) AS open_ticket_count,  CAST(lt.last_message_at AS date) AS latest_ticket_activity_date,  DATE '2026-01-05' - CAST(lt.last_message_at AS date) AS days_since_ticket_activityFROM holds hLEFT JOIN latest_payment_top lp ON lp.legal_hold_id = h.legal_hold_idLEFT JOIN open_tickets ot ON ot.legal_hold_id = h.legal_hold_idLEFT JOIN latest_ticket_top lt ON lt.legal_hold_id = h.legal_hold_idORDER BY days_since_placed DESC, h.tenant_nameORDER BY days_since_placed DESC NULLS FIRST, h.tenant_name NULLS LAST, h.legal_hold_id NULLS LAST
    WITH holds AS (
      SELECT lh.id AS legal_hold_id, lh.tenant_id AS tenant_id, lh.subject_user_id AS subject_user_id, lh.placed_at AS placed_at, t.name AS tenant_name
      FROM legal_holds lh
      JOIN tenants t ON t.id = lh.tenant_id
      WHERE lh.is_active = true
        AND t.name IN ('Marrowby & Vane', 'Rue Lafayette Studio', 'Cragsley Outfitters')
    ),
    latest_payment AS (
      SELECT h.legal_hold_id AS legal_hold_id, p.status AS status, p.updated_at AS updated_at, p.amount AS amount, p.currency_code AS currency_code,
             ROW_NUMBER() OVER (PARTITION BY h.legal_hold_id ORDER BY p.updated_at DESC NULLS FIRST, p.id DESC NULLS FIRST) AS rn
      FROM holds h
      JOIN orders o ON o.user_id = h.subject_user_id AND o.tenant_id = h.tenant_id
      JOIN payments p ON p.order_id = o.id
    ),
    latest_payment_top AS (
      SELECT * FROM latest_payment WHERE rn = 1
    ),
    open_tickets AS (
      SELECT h.legal_hold_id AS legal_hold_id, COUNT(*) AS open_ticket_count
      FROM holds h
      JOIN tickets tk ON tk.requester_user_id = h.subject_user_id AND tk.tenant_id = h.tenant_id
      WHERE tk.status NOT IN ('solved','closed')
      GROUP BY h.legal_hold_id
    ),
    latest_ticket AS (
      SELECT h.legal_hold_id AS legal_hold_id, tk.last_message_at AS last_message_at,
             ROW_NUMBER() OVER (PARTITION BY h.legal_hold_id ORDER BY tk.last_message_at DESC NULLS FIRST) AS rn
      FROM holds h
      JOIN tickets tk ON tk.requester_user_id = h.subject_user_id AND tk.tenant_id = h.tenant_id
    ),
    latest_ticket_top AS (
      SELECT * FROM latest_ticket WHERE rn = 1
    )
    SELECT
      h.tenant_name AS tenant_name,
      h.subject_user_id AS subject_user_id,
      CAST(h.placed_at AS date) AS hold_placed_date,
      DATE '2026-01-05' - CAST(h.placed_at AS date) AS days_since_placed,
      lp.status AS latest_payment_status,
      CAST(lp.updated_at AS date) AS latest_payment_updated_date,
      lp.amount AS latest_payment_amount,
      lp.currency_code AS latest_payment_currency,
      COALESCE(ot.open_ticket_count, 0) AS open_ticket_count,
      CAST(lt.last_message_at AS date) AS latest_ticket_activity_date,
      DATE '2026-01-05' - CAST(lt.last_message_at AS date) AS days_since_ticket_activity
    FROM holds h
    LEFT JOIN latest_payment_top lp ON lp.legal_hold_id = h.legal_hold_id
    LEFT JOIN open_tickets ot ON ot.legal_hold_id = h.legal_hold_id
    LEFT JOIN latest_ticket_top lt ON lt.legal_hold_id = h.legal_hold_id
    ORDER BY days_since_placed DESC NULLS FIRST, h.tenant_name NULLS LAST, h.legal_hold_id NULLS LAST
    10 ms100 ms1 sHyper66.7 msDuckDB41.2 msGizmoSQL51.4 msclickhouse_brew214 msFirebolt202 msDataFusion261 msClickHouse147 ms
  8. Everything, as recorded

    The agents' own records, as the role play wrote them; only the personal data of the person who ran it is redacted

    Ines's whole session, 7 turns
    • The request, as Ines received it
      Report request from Priyanka Desai (analyst for the Data Protection Officer):
      
      Title: Evidence check on the 3 legal-hold-linked chargeback disputes
      Question: For the 3 accounts under a payment-dispute legal hold, what internal evidence (payment status, support ticket activity) suggests whether the underlying dispute is still active or has gone stale?
      Grain: one row per legal hold (3 rows: Marrowby & Vane, Rue Lafayette Studio, Cragsley Outfitters)
      Columns:
      - tenant name
      - subject_user_id
      - hold placed_at (date)
      - days since placed (2026-01-05 minus placed_at)
      - latest payment status for this user (most recent by updated_at, via orders.user_id = subject_user_id joined to payments)
      - latest payment updated_at (date)
      - latest payment amount and currency
      - open ticket count for this user (tickets.requester_user_id, status not in solved/closed)
      - most recent ticket last_message_at for this user (date)
      - days since that last ticket activity
      Details: Source: legal_holds (the 3 active rows identified last week) joined by subject_user_id to orders -> payments (most recent payment by updated_at for that user) and to tickets (requester_user_id = subject_user_id). legal_holds has no populated entity_schema/entity_table/entity_id for these rows, so there's no direct link to a specific disputed payment — this report approximates by looking at the user's most recent payment activity and most recent support ticket activity as indirect evidence of whether the case is still live or has gone quiet. Use literal date 2026-01-05 for age math. Order by days since placed, descending.
      
      Check your query with the warehouse's dry_run tool, then hand it in with submit.
    • Ines calls dry_run
      WITH holds AS (
        SELECT lh.id AS legal_hold_id, lh.tenant_id, lh.subject_user_id, lh.placed_at, t.name AS tenant_name
        FROM legal_holds lh
        JOIN tenants t ON t.id = lh.tenant_id
        WHERE lh.is_active = true
          AND t.name IN ('Marrowby & Vane', 'Rue Lafayette Studio', 'Cragsley Outfitters')
      ),
      latest_payment AS (
        SELECT h.legal_hold_id, p.status, p.updated_at, p.amount, p.currency_code,
               ROW_NUMBER() OVER (PARTITION BY h.legal_hold_id ORDER BY p.updated_at DESC) AS rn
        FROM holds h
        JOIN orders o ON o.user_id = h.subject_user_id AND o.tenant_id = h.tenant_id
        JOIN payments p ON p.order_id = o.id
      ),
      latest_payment_top AS (
        SELECT * FROM latest_payment WHERE rn = 1
      ),
      open_tickets AS (
        SELECT h.legal_hold_id, COUNT(*) AS open_ticket_count
        FROM holds h
        JOIN tickets tk ON tk.requester_user_id = h.subject_user_id AND tk.tenant_id = h.tenant_id
        WHERE tk.status NOT IN ('solved','closed')
        GROUP BY h.legal_hold_id
      ),
      latest_ticket AS (
        SELECT h.legal_hold_id, tk.last_message_at,
               ROW_NUMBER() OVER (PARTITION BY h.legal_hold_id ORDER BY tk.last_message_at DESC) AS rn
        FROM holds h
        JOIN tickets tk ON tk.requester_user_id = h.subject_user_id AND tk.tenant_id = h.tenant_id
      ),
      latest_ticket_top AS (
        SELECT * FROM latest_ticket WHERE rn = 1
      )
      SELECT
        h.tenant_name,
        h.subject_user_id,
        CAST(h.placed_at AS date) AS hold_placed_date,
        DATE '2026-01-05' - CAST(h.placed_at AS date) AS days_since_placed,
        lp.status AS latest_payment_status,
        CAST(lp.updated_at AS date) AS latest_payment_updated_date,
        lp.amount AS latest_payment_amount,
        lp.currency_code AS latest_payment_currency,
        COALESCE(ot.open_ticket_count, 0) AS open_ticket_count,
        CAST(lt.last_message_at AS date) AS latest_ticket_activity_date,
        DATE '2026-01-05' - CAST(lt.last_message_at AS date) AS days_since_ticket_activity
      FROM holds h
      LEFT JOIN latest_payment_top lp ON lp.legal_hold_id = h.legal_hold_id
      LEFT JOIN open_tickets ot ON ot.legal_hold_id = h.legal_hold_id
      LEFT JOIN latest_ticket_top lt ON lt.legal_hold_id = h.legal_hold_id
      ORDER BY days_since_placed DESC, h.tenant_name
    • The warehouse answers
      STATUS: COMPILES (dry run on the empty schema, no data read)
      COLUMNS: tenant_name, subject_user_id, hold_placed_date, days_since_placed, latest_payment_status, latest_payment_updated_date, latest_payment_amount, latest_payment_currency, open_ticket_count, latest_ticket_activity_date, days_since_ticket_activity
    • InesQuery compiles with the expected 11 columns at the requested grain. Submitting.
    • Ines calls submit
      WITH holds AS (
        SELECT lh.id AS legal_hold_id, lh.tenant_id, lh.subject_user_id, lh.placed_at, t.name AS tenant_name
        FROM legal_holds lh
        JOIN tenants t ON t.id = lh.tenant_id
        WHERE lh.is_active = true
          AND t.name IN ('Marrowby & Vane', 'Rue Lafayette Studio', 'Cragsley Outfitters')
      ),
      latest_payment AS (
        SELECT h.legal_hold_id, p.status, p.updated_at, p.amount, p.currency_code,
               ROW_NUMBER() OVER (PARTITION BY h.legal_hold_id ORDER BY p.updated_at DESC) AS rn
        FROM holds h
        JOIN orders o ON o.user_id = h.subject_user_id AND o.tenant_id = h.tenant_id
        JOIN payments p ON p.order_id = o.id
      ),
      latest_payment_top AS (
        SELECT * FROM latest_payment WHERE rn = 1
      ),
      open_tickets AS (
        SELECT h.legal_hold_id, COUNT(*) AS open_ticket_count
        FROM holds h
        JOIN tickets tk ON tk.requester_user_id = h.subject_user_id AND tk.tenant_id = h.tenant_id
        WHERE tk.status NOT IN ('solved','closed')
        GROUP BY h.legal_hold_id
      ),
      latest_ticket AS (
        SELECT h.legal_hold_id, tk.last_message_at,
               ROW_NUMBER() OVER (PARTITION BY h.legal_hold_id ORDER BY tk.last_message_at DESC) AS rn
        FROM holds h
        JOIN tickets tk ON tk.requester_user_id = h.subject_user_id AND tk.tenant_id = h.tenant_id
      ),
      latest_ticket_top AS (
        SELECT * FROM latest_ticket WHERE rn = 1
      )
      SELECT
        h.tenant_name,
        h.subject_user_id,
        CAST(h.placed_at AS date) AS hold_placed_date,
        DATE '2026-01-05' - CAST(h.placed_at AS date) AS days_since_placed,
        lp.status AS latest_payment_status,
        CAST(lp.updated_at AS date) AS latest_payment_updated_date,
        lp.amount AS latest_payment_amount,
        lp.currency_code AS latest_payment_currency,
        COALESCE(ot.open_ticket_count, 0) AS open_ticket_count,
        CAST(lt.last_message_at AS date) AS latest_ticket_activity_date,
        DATE '2026-01-05' - CAST(lt.last_message_at AS date) AS days_since_ticket_activity
      FROM holds h
      LEFT JOIN latest_payment_top lp ON lp.legal_hold_id = h.legal_hold_id
      LEFT JOIN open_tickets ot ON ot.legal_hold_id = h.legal_hold_id
      LEFT JOIN latest_ticket_top lt ON lt.legal_hold_id = h.legal_hold_id
      ORDER BY days_since_placed DESC, h.tenant_name
    • The warehouse answers
      Submitted to tonight's batch. Your work on this request is done.
    • InesSubmitted. The report joins the 3 payment-dispute legal holds (Marrowby & Vane, Rue Lafayette Studio, Cragsley Outfitters) to each subject user's most recent payment and ticket activity as indirect evidence of dispute freshness, ordered by days since the hold was placed (most stale first). Note: since legal_holds doesn't link to a specific payment/ticket for these rows, this is an approximation using the user's overall latest activity, as I flagged in the submit note.