{
 "rows": [
  {
   "revision": 0,
   "kept": true,
   "words": 0,
   "right": 59,
   "of": 72,
   "note": ""
  },
  {
   "revision": 1,
   "kept": false,
   "words": 291,
   "right": 70,
   "of": 72,
   "lost": 2,
   "note": "Answer directly with SQL; these questions are answerable, so do not ask for clarification. Pick the most natural reading using the rules below.\n\nTransactions:\n- Count only status='posted'. Months are decided by posted_at, using a half-open range: posted_at >= TIMESTAMP 'YYYY-MM-01' AND posted_at < first day of the next month. Do not use occurred_at.\n- event_kind values include 'deposit' and 'transfer'. Use 'transfer', not 'internal_transfer'. Internal transfers have event_kind='transfer'. Each transfer has two legs that share a transfer_group_id.\n- direction is 'credit' or 'debit'. A signed amount is +amount_minor for credit and -amount_minor for debit.\n- \"Deposit amount\" means SUM(amount_minor) where event_kind='deposit'.\n- \"Net external cash flow\" means the signed sum over all posted events where event_kind <> 'transfer'.\n- To count each transfer once:\n  - For volume, sum the direction='debit' legs only.\n  - For counts, use COUNT(DISTINCT transfer_group_id).\n- Filter on the currency column.\n- Wrap a single-value sum in COALESCE(...,0).\n\nCard spend:\n- Use card_spend_daily.net_spend_minor, filtered by spend_date and currency.\n- To get organization, join accounts on account_id and take accounts.organization_id.\n- Group by organization, returning only organizations that have activity.\n\nCards:\n- A card is active when card_status='active'.\n- \"Account currency\" is accounts.currency.\n- To keep groups that have zero cards, start from accounts and LEFT JOIN cards with the status condition in the ON clause, then use COUNT(c.card_id).\n- \"At the snapshot\" means current table state, with no date filter.\n\nBalances / reconciliation:\n- Use account_daily, grouped by currency.\n- Opening balance = SUM(opening_minor) on the first day of the period.\n- Movement = SUM(posted_credit_minor - posted_debit_minor) over the period.\n- Closing balance = SUM(closing_minor) on the last day of the period.\n\nOutput: return only the requested columns, in the order asked, with amounts in minor units."
  },
  {
   "revision": 2,
   "kept": true,
   "words": 273,
   "right": 72,
   "of": 72,
   "lost": 0,
   "note": "Always answer with one SELECT; never ask for clarification. Use these defaults.\n\nValues: transactions.event_kind uses short names such as 'deposit', 'purchase', 'transfer' (not 'internal_transfer' or 'external_cash'). status uses 'posted', 'void' and similar (not 'completed'). direction is 'credit' or 'debit'. card_status 'active'.\n\nPeriods: use half-open ranges (>= first day, < first day of next month). For completed, posted or settled money (deposits, cash flow, transfers), use status='posted' and filter on posted_at. When the question names another status (void, pending) or says initiated or occurred, filter that status and use occurred_at. Do not mix the two.\n\nAmounts: credit is positive and debit is negative for signed totals. Wrap sums in COALESCE(...,0).\n- Deposit amount: event_kind='deposit', posted, SUM(amount_minor).\n- Net external cash flow: all posted rows with event_kind <> 'transfer', signed by direction.\n- Internal transfers: event_kind='transfer', posted. Volume, counted once, is SUM(amount_minor) of direction='debit' legs. Count is COUNT(DISTINCT transfer_group_id).\n- Event count or amount for a kind and status: COUNT(*), SUM(amount_minor) from transactions.\n\nCard spend: use card_spend_daily filtered on spend_date and its currency column. Gross spend is SUM(purchased_minor). Net spend is SUM(net_spend_minor). Refunds are refunded_minor. For an organization breakdown, join accounts on account_id and group by organization_id. Include only organizations with activity.\n\nCards: to count per account currency while keeping zero groups, use accounts LEFT JOIN cards ON account_id with the card_status condition placed inside the ON clause, and COUNT(c.card_id).\n\nLedger balances: use account_daily. Opening is opening_minor on the period's first balance_date. Movement is SUM(posted_credit_minor - posted_debit_minor) over the period. Closing is closing_minor on the last day. Group by currency.\n\nShape: return only the requested columns, one row per group, and amounts in minor units."
  },
  {
   "revision": 3,
   "kept": false,
   "stopped": "no failures left"
  }
 ],
 "final_right": 72,
 "of": 72
}
