Independent synthetic fixture values, complete membership and required field types; not production or human usefulness.

Generation confidence; semantic correctness is only verified by the listed checks.

Generation confidence is not an answer certificate.

The entire question interpretation has not been independently verified.

accounts IS the canonical CT user table: accounts.id EQUALS user_id. Carries relationship_manager_id and latest_pipedrive_activity_at. A REFERRER is an account referenced by another account's affiliate_id (refer-and-earn referrer when referrer.role='User'; 'referrer(s)' is a CT concept, NEVER the Pipedrive cf_referrer custom field — same suppression as 'partners'). NAME EXPOSURE (ruling 2026-07-08): individual first/last name and company name MAY be SHOWN in result rows to anyone with vault access (the vault boundary IS the authorization) — they are filled server-side post-execution as a display column (client_name / first_name / last_name / company_name placeholders), NEVER read via model-generated SQL (the CT-leg gate rejects a physical read; the model projects `NULL AS <col>`). CONTACT PII stays intentionally NOT exposed: email, telephone/phone and IPs are never shown in results (they remain WHERE-only filters where already allowed).

Project `id AS user_id` (accounts.id is the user key); one row per user already.

System: CT

accounts

Onboarding/client dimension keyed by user_id (= accounts.id). Declared (not traded) currencies live here.

Direct user_id; one row per user_id already. Project user_id first.

System: CT

client

Semantic: federated planning failed: Logged activities live in the Pipedrive activity log, but this question groups or filters by a CurrencyTransfer-only dimension (sales stream, currency, campaign, or a live CT cohort) that only exists on the trading side — combining the two per-client isn't supported yet, and I won't silently answer with trade or referral counts instead. Try 'activity volume by owner' for the event log, or ask that breakdown against a trading measure (e.g. 'realized revenue by sales stream'). Name the group, measure, and date window in a new question.

activation-definition activation-definition-gold onboarding-duration declared-currency-intent client-type-sti-classes

How many distinct ordinary CT user accounts opted in to marketing emails whose registration is still incomplete are there? Return client_count, including zero if none qualify.


System: CT

CT accounts

The trade's PAYMENT/LIQUIDITY PARTNER — CT calls this the BROKER (live names include Corpay, Corpay Offline, Currencycloud, Clear Treasury, Moneycorp, Verto, iBan First, Central FX). Resolve the partner NAME by joining: JOIN public.broker_accounts ba ON ba.id = tb.broker_account_id JOIN public.brokers b ON b.id = ba.broker_id, then use b.name as the partner dimension (GROUP BY b.name for a by-partner breakdown; every trade_bookings row carries broker_account_id). NEVER use trade_bookings.platform for a partner/provider/broker breakdown — platform is the booking CHANNEL (web/ios/system/nexus), not a partner — and never alias platform AS payment_partner.

Direct user_id; group trade rows to one per user_id (COUNT(*) FILTER (WHERE status <> 'closed') for the default booked trade count; a settled-gated count ONLY when the user explicitly says settled). Window REALIZED money metrics (settled commission/revenue, daily run-rate, realized QoQ) on completed_at with status='settled' — NOT settlement_at (the deadline) and NOT traded_at (booking date). Use traded_at only for booking-date questions.

System: CT

broker

System: CT

client

Sql: The generated SQL could not complete the requested query. Try the query again in a few moments

SELECT COALESCE(SUM(CASE WHEN notified_user_id IS NOT NULL AND notified_user_id NOT IN (SELECT user_id FROM public.broker_accounts WHERE verified_at IS NOT NULL) THEN 1 ELSE 0 END), 0) AS client_count FROM (SELECT DISTINCT ba.user_id AS notified_user_id FROM public.broker_accounts ba WHERE ba.notified_at IS NOT NULL) n

SELECT client_count FROM (SELECT CAST(0 AS INT) AS client_count) AS s LIMIT 10000

churn-tier-definitions declared-currency-intent trade-existence-default-booked settlement-is-ct-trade-lifecycle client-type-sti-classes

How many distinct CT accounts of any role with a notified broker account but no broker account that has ever been verified are there? Return client_count, including zero if none qualify.

The query failed to run. This could be due to a database issue or invalid data in your query.


Zero CT accounts have a verified broker account dated after their completed registration.

How many distinct CT accounts of any role whose ea...

System: CT

CT accounts

System: CT

broker

signup-date mis-binding fix (created_at vs first_activated_at)

System: CT

registration date

System: CT

client

Metric match

No predefined metrics are configured for this connection — scored on time clarity, query complexity and column visibility instead

SELECT COUNT(DISTINCT a.id) AS client_count FROM public.accounts a JOIN public.clients c ON c.user_id = a.id JOIN (SELECT user_id, MIN(verified_at) AS first_verified_at FROM public.broker_accounts WHERE verified_at IS NOT NULL GROUP BY user_id) fvb ON fvb.user_id = a.id WHERE c.completed_registration_at IS NOT NULL AND fvb.first_verified_at > c.completed_registration_at

SELECT
  COUNT(DISTINCT a.id) AS client_count
FROM public.accounts AS a
JOIN public.clients AS c
  ON c.user_id = a.id
JOIN (
  SELECT
    user_id,
    MIN(verified_at) AS first_verified_at
  FROM public.broker_accounts
  WHERE
    NOT verified_at IS NULL
  GROUP BY
    user_id
) AS fvb
  ON fvb.user_id = a.id
WHERE
  NOT c.completed_registration_at IS NULL
  AND fvb.first_verified_at > c.completed_registration_at

Earliest verified broker account = the minimum non-null verified_at across broker_accounts per user.

Counts accounts of any role joined to clients with a non-null completed registration date.

Reading this as the registration-form funnel — started the signup wizard vs finished it (clients.completed_registration_at). If you meant activation (verified & ready to trade), say so.

All matched clients have at least one broker verification on or before their registration completion date.

activation-definition activation-definition-gold onboarding-duration churn-tier-definitions declared-currency-intent trade-existence-default-booked settlement-is-ct-trade-lifecycle client-type-sti-classes trade-existence-gold-booked

How many distinct CT accounts of any role whose earliest verified broker account date is after their completed registration date are there? Return client_count, including zero if none qualify.

Join accounts to clients on the client's user_id matching the account id.

Build a helper list from broker_accounts keeping only rows where verified_at is not null, and for each user take their earliest verified_at as first_verified_at.

Attach that helper list to accounts by user_id, so only accounts with at least one verified broker account survive.

Keep only rows where completed_registration_at is not null (registration must be completed).

Keep only rows where first_verified_at is later than completed_registration_at.

Count the distinct account ids and report the result as client_count.

Summary: Count distinct account IDs that have a completed registration and an earliest verified broker account date that falls after that registration date.


System: CT

CT accounts

System: CT

broker

System: CT

client

Semantic: The query could not preserve the requested meaning or scope. Try the query again in a few moments

```json
{
  "sql": "",
  "explanation": "The provided schema lists table names but no columns, and no column exists (in the visible schema or curated knowledge) indicating broker-account verification status or an 'outdated' marker, so I cannot confidently build this query.",
  "confidence": "uncerta

How many distinct CT accounts of any role with a previously verified broker account now marked outdated are there? Return client_count, including zero if none qualify.


System: CT

CT accounts

System: CT

brokers

System: CT

client

```json
{
  "sql": "",
  "explanation": "The question requires counting distinct CT accounts by verified broker relationships, but the schema context provides no column definitions for broker_accounts/clients (empty column lists) and the referenced ct.client_360 is not available, so a valid query ca

How many distinct CT accounts of any role that have at least two different verified brokers are there? Return client_count, including zero if none qualify.


System: CT

client

```json
{
  "sql": "",
  "explanation": "The request requires the ct.client_360 view with declared currency fields, but the provided schema lists no columns for any table and no client_360 object, so I cannot generate a valid query.",
  "confidence": "uncertain",
  "warnings": ["Schema context conta

How many distinct private CT client records who declared at least one currency on both the sell and buy sides are there? Return client_count, including zero if none qualify.


There are 4 distinct corporate CT client records with completed registration and no non-deleted, non-closed booking.

How many distinct corporate CT client records with...

System: CT

client

Query complexity

Moderate complexity: 1 JOINs, subqueries

High confidence (85%) — moderate complexity

SELECT COUNT(*) AS client_count FROM public.accounts a JOIN public.clients c ON c.user_id = a.id WHERE a.role = 'User' AND NOT a.skip_commission_calculations IS TRUE AND c.type IS NOT NULL AND c.type <> 'PersonalAccount' AND c.completed_registration_at IS NOT NULL AND NOT EXISTS (SELECT 1 FROM public.trade_bookings tb WHERE tb.user_id = a.id AND tb.status <> 'closed' AND tb.deleted_at IS NULL)

SELECT
  COUNT(*) AS client_count
FROM public.accounts AS a
JOIN public.clients AS c
  ON c.user_id = a.id
WHERE
  a.role = 'User'
  AND NOT a.skip_commission_calculations IS TRUE
  AND NOT c.type IS NULL
  AND c.type <> 'PersonalAccount'
  AND NOT c.completed_registration_at IS NULL
  AND NOT EXISTS(
    SELECT
      1
    FROM public.trade_bookings AS tb
    WHERE
      tb.user_id = a.id AND tb.status <> 'closed' AND tb.deleted_at IS NULL
  )

Corporate = client type is non-null and not 'PersonalAccount'

Excludes accounts flagged to skip commission calculations and accounts other than role 'User'

List those 4 client records with their names, registration dates and any closed/deleted booking history

How many of these 4 registered in the last 90 days?

The figure counts client records (user_id joins), not necessarily distinct corporate entities — one entity could hold several records.

A client with only closed or deleted bookings still qualifies, so these may include previously active clients, not purely never-traded ones.

How many distinct corporate CT client records with completed registration who have no non-deleted, non-closed booking are there? Return client_count, including zero if none qualify.

Joins accounts to clients by matching clients.user_id to accounts.id.

Keeps only accounts with role 'User' where skip_commission_calculations is not true.

Keeps only clients whose type is filled in and is not 'PersonalAccount', and who have a completed_registration_at timestamp.

Excludes any client who has even one trade_booking row with their user_id that is not 'closed' and has no deleted_at timestamp.

Returns the number of remaining clients as client_count (zero if none qualify).

Summary: Counts clients whose completed-registration, non-personal corporate accounts have no active, non-deleted booking.


System: CT

client

System: CT

client type

System: CT

broker

Sql: The generated SQL could not complete the requested query. Retry after CT data is available.

SELECT COUNT(*) AS client_count FROM public.clients c WHERE (c.type IS NULL OR c.type = '') AND EXISTS (SELECT 1 FROM public.broker_accounts ba WHERE ba.user_id = c.user_id)

SELECT user_id FROM ct.client_360 WHERE (client_type IS NULL OR client_type = 'unknown') AND broker_account_count > 0 GROUP BY user_id LIMIT 10000

churn-tier-definitions declared-currency-intent trade-existence-default-booked settlement-is-ct-trade-lifecycle activation-definition-gold client-type-sti-classes trade-existence-gold-booked

How many distinct CT client records whose client type is unknown and who have at least one broker account are there? Return client_count, including zero if none qualify.

CT data unavailable: the CT leg returned no join key 'user_id'; a whole-book result cannot answer the selected cohort


Zero CT accounts have system-generated quotes without any user-requested quote (client_count = 0).

How many distinct CT accounts of any role that hav...

System: CT

CT accounts

Quote-level rows with DIRECT user_id (= accounts.id). No account_id column. type is by_client/admin_ping/rate_alert/rsi_alert — a quote a user MADE = type 'by_client' only (rate-alert/RSI/admin pings are system rows, ~40% of the table). status booked/pending; a booked quote converted to a trade (trade_bookings.quote_id = quotes.id).

Direct user_id; group quote metrics to one row per user_id before merge.

System: CT

quotes

System: CT

client

SELECT COUNT(DISTINCT a.id) AS client_count FROM public.accounts a WHERE EXISTS (SELECT 1 FROM public.quotes q WHERE q.user_id = a.id AND q.type <> 'by_client') AND NOT EXISTS (SELECT 1 FROM public.quotes q2 WHERE q2.user_id = a.id AND q2.type = 'by_client')

SELECT
  COUNT(DISTINCT a.id) AS client_count
FROM public.accounts AS a
WHERE
  EXISTS(
    SELECT
      1
    FROM public.quotes AS q
    WHERE
      q.user_id = a.id AND q.type <> 'by_client'
  )
  AND NOT EXISTS(
    SELECT
      1
    FROM public.quotes AS q2
    WHERE
      q2.user_id = a.id AND q2.type = 'by_client'
  )

System-generated quotes are defined as quotes with type <> 'by_client'; user-requested quotes as type = 'by_client'.

How many distinct accounts have any system-generated quotes at all, regardless of client quotes?

Every account with a non-by_client quote also has at least one by_client quote, so there is no untouched-by-client segment here.

Single-row aggregate, so this is a definitive count for the period covered, not a sample.

How many distinct CT accounts of any role that have system-generated quotes and no user-requested quote are there? Return client_count, including zero if none qualify.

Reads the accounts table and counts distinct values of its id column, reported as client_count.

Keeps an account only if there exists at least one row in quotes linked to it (quotes.user_id = accounts.id) whose type is anything other than 'by_client'.

Also requires that no quotes row linked to the account has type exactly 'by_client'.

If no accounts meet both conditions, the count is zero.

Summary: Counts distinct account IDs that have at least one quote not of type 'by_client' and no quotes of type 'by_client'.


Zero CT accounts have a user-requested quote predating their earliest broker verification timestamp.

How many distinct CT accounts of any role whose us...

System: CT

CT accounts

System: CT

quote

System: CT

broker

System: CT

client

Medium confidence (73%) — clear time period, complex query

SELECT COUNT(*) AS client_count FROM (SELECT a.id FROM public.accounts AS a JOIN (SELECT user_id, MIN(created_at) AS first_quote_at FROM public.quotes WHERE type = 'by_client' AND NOT quotes.user_id IN (SELECT id FROM public.accounts WHERE id = 1 OR email ILIKE '%@currencytransfer.com') GROUP BY user_id) AS q ON q.user_id = a.id JOIN (SELECT user_id, MIN(verified_at) AS first_verified_at FROM public.broker_accounts WHERE NOT verified_at IS NULL GROUP BY user_id) AS v ON v.user_id = a.id WHERE q.first_quote_at < v.first_verified_at) AS t

SELECT
  COUNT(*) AS client_count
FROM (
  SELECT
    a.id
  FROM public.accounts AS a
  JOIN (
    SELECT
      user_id,
      MIN(created_at) AS first_quote_at
    FROM public.quotes
    WHERE
      type = 'by_client'
      AND NOT quotes.user_id IN (
        SELECT
          id
        FROM public.accounts
        WHERE
          id = 1 OR email ILIKE '%@currencytransfer.com'
      )
    GROUP BY
      user_id
  ) AS q
    ON q.user_id = a.id
  JOIN (
    SELECT
      user_id,
      MIN(verified_at) AS first_verified_at
    FROM public.broker_accounts
    WHERE
      NOT verified_at IS NULL
    GROUP BY
      user_id
  ) AS v
    ON v.user_id = a.id
  WHERE
    q.first_quote_at < v.first_verified_at
) AS t

Only client-initiated quotes (type = 'by_client') count as user-requested; broker-issued quotes are excluded.

Accounts with id 1 or an @currencytransfer.com email (internal/test) are excluded, and broker verifications with a null verified_at are ignored.

client_count is exactly 0, so every matched account's first client quote came at or after their first verification (or the two events never co-occur for the same user).

How many distinct CT accounts of any role whose user-requested quote predates their earliest known broker verification timestamp are there? Return client_count, including zero if none qualify.

From the quotes table, keep only quotes of type 'by_client', and drop any quote whose user appears in the inner account check — specifically, accounts whose id equals 1 or whose email contains '@currencytransfer.com' (c…

For each remaining user, find their earliest quote timestamp (first_quote_at).

From the broker_accounts table, skip rows with no verification timestamp, and for each user find their earliest verified_at (first_verified_at).

Join both per-user results to the accounts table on user_id matching the account id.

Keep only accounts where the earliest quote came before the earliest verification.

Count those accounts and return the number as client_count (zero if none match).

Summary: Counts how many accounts have a user-requested quote timestamped before that same user's earliest broker verification timestamp.


58 distinct CT accounts have a quote-linked booking that is neither closed nor deleted

How many distinct CT accounts of any role whose ow...

System: CT

CT accounts

System: CT

quote

System: CT

quote ID

System: CT

client

SELECT COUNT(DISTINCT a.id) AS client_count FROM public.accounts AS a JOIN public.quotes AS q ON q.user_id = a.id AND q.type = 'by_client' JOIN public.trade_bookings AS tb ON tb.quote_id = q.id AND (tb.status <> 'closed' AND tb.deleted_at IS NULL) AND tb.user_id = a.id WHERE NOT a.id IN (SELECT id FROM public.accounts WHERE id = 1 OR email ILIKE '%@currencytransfer.com')

SELECT
  COUNT(DISTINCT a.id) AS client_count
FROM public.accounts AS a
JOIN public.quotes AS q
  ON q.user_id = a.id AND q.type = 'by_client'
JOIN public.trade_bookings AS tb
  ON tb.quote_id = q.id
  AND (
    tb.status <> 'closed' AND tb.deleted_at IS NULL
  )
  AND tb.user_id = a.id
WHERE
  NOT a.id IN (
    SELECT
      id
    FROM public.accounts
    WHERE
      id = 1 OR email ILIKE '%@currencytransfer.com'
  )

Booking attribution means the booking's user_id matches the account that raised the quote

Non-qualifying statuses are excluded by filtering out closed bookings and soft-deleted bookings, not by requiring an 'open' status

List those 58 accounts with their booking counts and values

How many of these bookings are in each non-closed status?

How has this count trended month by month so far in 2026?

Each account's own quote (type 'by_client') had to convert to a booking linked by quote ID and belonging to the same account, so indirect or role-based attribution is not counted

Admin (id 1) and any account with a currencytransfer.com email are excluded from the count

How many distinct CT accounts of any role whose own quote converted to a non-deleted, non-closed booking through the quote ID link are there? Return client_count, including zero if none qualify.

Joins quotes where the quote's user is the account and the quote type is 'by_client'.

Joins trade_bookings where the booking's quote matches that quote, the booking's user is the same account, the status isn't 'closed', and deleted_at is empty.

Excludes account id 1 and any account whose email contains '@currencytransfer.com'.

Counts the distinct account ids and returns that single number as client_count.

Summary: Counts distinct accounts linked through their own client-created quotes to a booking that isn't closed or deleted, excluding test/internal accounts.


System: CT

CT accounts

System: CT

client

```json
{
  "sql": "",
  "explanation": "The request requires tables (ct.client_360, pipedrive.*) and booking-status columns that are not present in the provided schema, so a valid query cannot be generated.",
  "confidence": "uncertain",
  "warnings": ["Referenced tables ct.client_360 and pipedrive

How many distinct CT accounts of any role with a non-deleted booking but no settled booking are there? Return client_count, including zero if none qualify.


System: CT

CT accounts

System: CT

client

```json
{
  "sql": "",
  "explanation": "The request requires the ct.client_360 table (per the federation gold-leg instruction) and columns such as trade booking invoice/status fields, but the provided schema contains no ct.client_360 table and lists no columns for any table, so no valid query can b

How many distinct CT accounts of any role with an invoiced booking record that is neither closed nor settled, including records marked deleted are there? Return client_count, including zero if none qualify.


System: CT

CT accounts

System: CT

client

```json
{
  "sql": "",
  "explanation": "The provided schema lists no columns for any table and does not include ct.client_360, so I cannot confidently build the required query.",
  "confidence": "uncertain",
  "warnings": ["No column metadata available (accounts.is_deleted, trade_bookings.deleted,

How many distinct CT accounts of any role whose account is not deleted but who have a deleted booking are there? Return client_count, including zero if none qualify.


System: CT

CT accounts

System: CT

client

```json
{
  "sql": "",
  "explanation": "The federation leg restricts output to ct.client_360 and pipedrive.* fields, but no column information for ct.client_360 (or any table) was provided in the schema context, so the pre-billable measure fields and user_id column cannot be reliably referenced.",

How many distinct CT accounts of any role with pre-billable bookings that qualify for the CT statistics filters are there? Return client_count, including zero if none qualify.


System: CT

CT accounts

GBP conversion rate for the sell leg. CT-report stats filter excludes trades where this IS NULL (commission cannot be converted to GBP).

System: CT

sell-currency-to-GBP rate

System: CT

client

```json
{
  "sql": "",
  "explanation": "The gold leg restricts sources to ct.client_360 and pipedrive.*, but identifying settled bookings lacking a sell-currency-to-GBP rate requires ct.trade_bookings/trade_details columns (status='settled', rate fields) that are not provided in the schema.",
  "co

How many distinct CT accounts of any role with a settled booking that has no sell-currency-to-GBP rate are there? Return client_count, including zero if none qualify.


5 distinct CT accounts have negative total known realized commission on settled trades.

How many distinct CT accounts of any role whose su...

System: CT

CT accounts

CT realized commission in GBP — THE canonical CT revenue measure. SUM(commission) over trades whose trade_bookings.status='settled', grouped by trade_bookings.user_id. NEVER use settlement/sell/buy amount as revenue.

Join trade_booking_id -> trade_bookings.id, then GROUP BY trade_bookings.user_id. Realized GBP revenue = SUM(commission) where trade_bookings.status='settled'. Date realized-revenue windows on trade_bookings.completed_at (actual settlement date), NOT settlement_at (deadline) or traded_at (booking).

System: CT

commission

System: CT

client

Medium confidence (69%) — implicit time period, moderate complexity

SELECT COALESCE(COUNT(*), 0) AS client_count FROM (SELECT tb.user_id FROM public.trade_bookings AS tb JOIN public.trade_details AS td ON td.trade_booking_id = tb.id WHERE tb.status = 'settled' AND NOT tb.user_id IN (SELECT id FROM public.accounts WHERE id = 1 OR email ILIKE '%@currencytransfer.com') GROUP BY tb.user_id HAVING SUM(td.commission) < 0) AS neg

SELECT
  COALESCE(COUNT(*), 0) AS client_count
FROM (
  SELECT
    tb.user_id
  FROM public.trade_bookings AS tb
  JOIN public.trade_details AS td
    ON td.trade_booking_id = tb.id
  WHERE
    tb.status = 'settled'
    AND NOT tb.user_id IN (
      SELECT
        id
      FROM public.accounts
      WHERE
        id = 1 OR email ILIKE '%@currencytransfer.com'
    )
  GROUP BY
    tb.user_id
  HAVING
    SUM(td.commission) < 0
) AS neg

'Realized commission' interpreted as commission on settled trade bookings only — non-settled statuses are excluded.

Accounts identified by trade_bookings user_id, and only commissions present in trade_details are included (missing commission rows are not treated as zero).

List those 5 accounts and their total negative commission.

How large is each account's commission shortfall in aggregate?

Each account is counted once, based on the summed commission across all its settled trade bookings, not per trade.

The list excludes internal CurrencyTransfer accounts (account id 1 and any @currencytransfer.com email addresses).

How many distinct CT accounts of any role whose sum of known realized commission is negative are there? Return client_count, including zero if none qualify.

Only trades with status 'settled' are considered.

Any user whose id is 1 or whose account email contains '@currencytransfer.com' is excluded.

Each user's commissions are added up across their matched bookings.

Only users whose total commission sum is negative are kept.

The result counts those users; if none qualify, the answer is zero.

Summary: Count how many distinct users have settled trade bookings whose total commission across their bookings is negative, excluding internal accounts, returning zero if none.


System: CT

CT accounts

System: CT

commission

System: CT

client

```json
{
  "sql": "",
  "explanation": "The provided schema lists table names but no columns, and the required ct.client_360 view is not defined, so I cannot confidently map 'commission inputs all unknown', booking status flags, or client_360 fields to real columns.",
  "confidence": "uncertain",

How many distinct CT accounts of any role with booking records, including closed and deleted records, whose commission inputs are all unknown are there? Return client_count, including zero if none qualify.


11 CT accounts have at least one booked commission input but a booked commission total of exactly zero.

How many distinct CT accounts of any role with at ...

System: CT

CT accounts

System: CT

commission

System: CT

client

Medium confidence (58%) — implicit time period, complex query

SELECT COUNT(*) AS client_count FROM (SELECT tb.user_id, COALESCE(SUM(td.commission), 0) AS booked_commission_total, COUNT(td.id) AS commission_input_rows FROM public.trade_bookings AS tb JOIN public.trade_details AS td ON td.trade_booking_id = tb.id JOIN public.accounts AS a ON a.id = tb.user_id WHERE (tb.status <> 'closed' AND NOT a.skip_commission_calculations IS TRUE AND NOT tb.sell_currency_to_gbp_rate IS NULL) AND NOT tb.user_id IN (SELECT id FROM public.accounts WHERE id = 1 OR email ILIKE '%@currencytransfer.com') GROUP BY tb.user_id HAVING COALESCE(SUM(td.commission), 0) = 0) AS zero_commission_clients

SELECT
  COUNT(*) AS client_count
FROM (
  SELECT
    tb.user_id,
    COALESCE(SUM(td.commission), 0) AS booked_commission_total,
    COUNT(td.id) AS commission_input_rows
  FROM public.trade_bookings AS tb
  JOIN public.trade_details AS td
    ON td.trade_booking_id = tb.id
  JOIN public.accounts AS a
    ON a.id = tb.user_id
  WHERE
    (
      tb.status <> 'closed'
      AND NOT a.skip_commission_calculations IS TRUE
      AND NOT tb.sell_currency_to_gbp_rate IS NULL
    )
    AND NOT tb.user_id IN (
      SELECT
        id
      FROM public.accounts
      WHERE
        id = 1 OR email ILIKE '%@currencytransfer.com'
    )
  GROUP BY
    tb.user_id
  HAVING
    COALESCE(SUM(td.commission), 0) = 0
) AS zero_commission_clients

'Any role' was interpreted as no role filter — all accounts passing the exclusions count.

'Known booked commission input' means at least one joined trade_details commission row exists, valued at zero or cancelling out.

List those 11 accounts with their commission input row counts and booking details.

How many of these accounts are non-closed versus other booking statuses?

A zero total with at least one commission row means commissions are offsetting or recorded as zero rather than absent.

The count excludes closed bookings, accounts with skip_commission_calculations set, bookings lacking a GBP conversion rate, and internal CurrencyTransfer accounts.

How many distinct CT accounts of any role with at least one known booked commission input and a booked commission total of exactly zero are there? Return client_count, including zero if none qualify.

Reads trade_bookings, each linked to its rows in trade_details via trade_booking_id, and links the booking's user_id to the accounts table.

Keeps only bookings that are not 'closed', whose account does not have skip_commission_calculations set to true, and that have a non-null GBP conversion rate.

Excludes any user_id belonging to an account with id 1 or an email containing '@currencytranslate.com' — here '%@currencytransfer.com'.

Groups by user_id and adds up each person's commission values (treating nulls as 0) and counts their commission rows.

Keeps only users whose commission total is exactly zero; COALESCE means missing commissions count as 0, not null.

The final count is how many such users there are, returning 0 if none qualify.

Summary: Counts how many distinct accounts (user_ids) have commission rows summing to exactly zero, after excluding closed bookings, flagged accounts, and internal Currencytransfer accounts.


System: CT

accounts

System: CT

client

```json
{
  "sql": "",
  "explanation": "The requested source table ct.client_360 is not present in the provided schema (all tables list no columns), so no valid query can be generated.",
  "confidence": "uncertain",
  "warnings": ["Referenced table ct.client_360 does not exist in the available sche

How many distinct ordinary CT user accounts created during September 2026 in Europe/London, interpreting raw timestamps as UTC are there? Return client_count, including zero if none qualify.


System: CT

CT accounts

When the trade completed/settled. Date column for the realized (settled) commission reading.

System: CT

completion date

The client's settlement DEADLINE (the must-settle-by date so the payment firm honours delivery) — NOT when revenue is realized. It is populated even on trades that have not settled yet (e.g. awaiting_funds). Do NOT date realized/settled money on this; use completed_at.

System: CT

settlement deadline

System: CT

client

Schema: The query refers to a table or column that is unavailable on the selected connection. Try the query again in a few moments

SELECT COUNT(DISTINCT tb.user_id) AS client_count FROM public.trade_bookings AS tb WHERE (tb.status = 'settled' AND NOT tb.completed_at IS NULL AND NOT tb.settlement_at IS NULL AND CAST(((tb.completed_at AT TIME ZONE 'UTC') AT TIME ZONE 'Europe/London') AS DATE) <> CAST(((tb.settlement_at AT TIME ZONE 'UTC') AT TIME ZONE 'Europe/London') AS DATE)) AND NOT tb.user_id IN (SELECT id FROM public.accounts WHERE id = 1 OR email ILIKE '%@currencytransfer.com')

SELECT COUNT(DISTINCT user_id)::int AS client_count FROM ct.client_360 WHERE status = 'settled' AND completed_at IS NOT NULL AND settlement_at IS NOT NULL AND (completed_at AT TIME ZONE 'Europe/London')::date <> (settlement_at AT TIME ZONE 'Europe/London')::date

```json
{
  "sql": "",
  "explanation": "The gold catalog contains no raw trade tables and ct.client_360 has no per-trade settlement status, completed_at, or settlement_at columns needed to compare completion date vs settlement deadline, so this leg cannot be answered from gold.",
  "confidence": "u

How many distinct CT accounts of any role with a settled booking whose actual completion date differs from its settlement deadline date in Europe/London, treating raw timestamps as UTC are there? Return client_count, including zero if none qualify.


System: CT

CT accounts

System: CT

broker

System: CT

client

SELECT COUNT(*) AS client_count FROM (SELECT tb.user_id FROM public.trade_bookings AS tb WHERE (tb.status <> 'closed' AND tb.deleted_at IS NULL) AND NOT tb.user_id IN (SELECT id FROM public.accounts WHERE id = 1 OR email ILIKE '%@currencytransfer.com') GROUP BY tb.user_id HAVING NOT MIN(tb.traded_at) IS NULL AND MIN(tb.traded_at) < (SELECT MIN(ba.verified_at) FROM public.broker_accounts AS ba WHERE ba.user_id = tb.user_id AND NOT ba.verified_at IS NULL)) AS q

SELECT c.user_id, COUNT(*) OVER () AS client_count FROM ct.client_360 c WHERE c.first_traded_at IS NOT NULL AND c.first_broker_verified_at IS NOT NULL AND c.first_traded_at < c.first_broker_verified_at GROUP BY c.user_id, c.first_traded_at, c.first_broker_verified_at

How many distinct CT accounts of any role whose first non-deleted, non-closed booking predates their first broker verification are there? Return client_count, including zero if none qualify.


Zero CT client records match the referral-plus-reward-event criteria, so no clients qualify.

How many distinct CT client records referred by a ...

System: CT

customer

System: CT

referrer

SELECT COUNT(DISTINCT a.id) AS client_count FROM public.accounts a JOIN public.accounts ref ON ref.id = a.affiliate_id JOIN public.reward_events re ON re.user_id = ref.id AND re.referred_user_id = a.id WHERE a.affiliate_id IS NOT NULL AND ref.role = 'User'

SELECT
  COUNT(DISTINCT a.id) AS client_count
FROM public.accounts AS a
JOIN public.accounts AS ref
  ON ref.id = a.affiliate_id
JOIN public.reward_events AS re
  ON re.user_id = ref.id AND re.referred_user_id = a.id
WHERE
  NOT a.affiliate_id IS NULL AND ref.role = 'User'

'Customer account' referrer interpreted as accounts with role = 'User' (staff/affiliate-role referrers excluded)

CT client records interpreted as rows in accounts where affiliate_id is set; only reward events matching the exact referrer-client pair are counted

How many clients have a referrer with role 'User' regardless of whether a reward event exists?

Which referral pairs have a reward event but a referrer whose role is not 'User'?

The joins require a two-way link: the client's referrer is a customer account and a reward event exists pairing that referrer with this specific client — none do.

A zero here means either the reward events are not logged against these referral pairs or the referral programme has not triggered rewards for customer-account referrers.

How many distinct CT client records referred by a customer account where that referrer has a reward event for the same client are there? Return client_count, including zero if none qualify.

Reads from accounts (aliased as a, the client), accounts again (aliased as ref, the referrer), and reward_events.

Keeps only client rows where affiliate_id is not null, i.e. excludes clients with no referrer recorded.

Joins ref to a by matching ref.id to a.affiliate_id, and requires ref.role = 'User'.

Joins reward_events where the event's user_id is the referrer's id and its referred_user_id is that same client's id.

Counts the number of distinct client ids that survive all these conditions, reported as client_count.

Summary: Count distinct client account records that have a referrer account, where the referrer is a 'User' and has a reward event tied to that same client.


32 distinct CT client records are counted as referred by a professional affiliate under this query's definition.

System: CT

client

Matview over public.affiliate_details. AFFILIATE-keyed dimension (keyed by affiliate_id), NOT a per-user/client fact table. It bridges to a client via client.affiliate_id = affiliate_details.affiliate_id, where client.affiliate_id -> accounts.id of the referrer (NOT the account_id bridge). One affiliate maps to many clients, so it CANNOT merge on the federation user_id; route it as an affiliate-dimension lookup (fail-safe), never fanned out or summed per user, until a hand-tuned attribution bridge exists. Refer-and-earn referrers are accounts.role='User' (accounts.role values include User 89179, Affiliate 442, Partner 50, AffiliateManager 11); commission_rate > 0 marks a professional affiliate. SECURITY: bank/PII columns (iban, account_number, sort_code, bic_swift, aba, bsb, address, bank_account_country) are never exposed in a CT federation leg.

System: CT

professional affiliate

Affiliate commission rate; commission_rate > 0 marks a professional affiliate.

System: CT

commission rate

SELECT COUNT(DISTINCT a.id) AS client_count FROM public.accounts a JOIN public.accounts ref ON ref.id = a.affiliate_id WHERE a.affiliate_id IS NOT NULL AND ref.role IN ('Affiliate','AffiliateManager','Partner')

SELECT
  COUNT(DISTINCT a.id) AS client_count
FROM public.accounts AS a
JOIN public.accounts AS ref
  ON ref.id = a.affiliate_id
WHERE
  NOT a.affiliate_id IS NULL
  AND ref.role IN ('Affiliate', 'AffiliateManager', 'Partner')

Professional affiliate = referrer account with role in ('Affiliate','AffiliateManager','Partner')

Zero commission rate is implied by this role-based definition rather than filtered directly on a commission field

Assuming "revenue" = booked trading revenue (commission on all non-cancelled trades) — includes open/forward trades not yet settled — say 'settled', 'realized', or 'billable' to narrow.

List those 32 clients with their referrer and each referrer's commission rate to confirm which truly have a zero rate

How does the 32 split across referrer role (Affiliate vs AffiliateManager vs Partner)?

The SQL filters on the referrer's role (Affiliate, AffiliateManager or Partner) but does not filter on commission rate being zero, so the 32 may include referrers with non-zero rates if any exist.

refer-and-earn-earnings-disambiguation affiliate-cohort-designator settlement-is-ct-trade-lifecycle declared-currency-intent client-type-sti-classes

How many distinct CT client records referred by a professional affiliate whose commission rate is zero are there? Return client_count, including zero if none qualify.

Reads the accounts table twice: once as 'a' (the client records) and once as 'ref' (the referrer, matched by a.affiliate_id = ref.id).

Only keeps rows where a.affiliate_id is filled in — records with no referrer are excluded.

Requires the matched referrer's role to be one of: Affiliate, AffiliateManager, or Partner.

Counts the number of distinct client ids that survive, returned as client_count (zero if none qualify).

Summary: Counts how many distinct client records have a referrer whose role is Affiliate, AffiliateManager, or Partner, ignoring rows with no referrer.


System: CT

accounts

Owning salesperson id (account-level). Used alongside relationship_manager_id to assign a client's sales 'stream'/team.

System: CT

salesperson

Owning relationship manager id (account-level).

System: CT

relationship manager

System: PD

people

System: CT

client

```json
{
  "sql": "",
  "explanation": "The requested source table ct.client_360 (and its salesperson/relationship-manager fields) is not present in the provided schema, and no table columns are available to build the query from.",
  "confidence": "uncertain",
  "warnings": ["ct.client_360 is not i

How many distinct ordinary CT user accounts whose salesperson and relationship manager are both known and are different people are there? Return client_count, including zero if none qualify.


43 distinct CT accounts with a campaign assignment and a known web referral domain qualify.

How many distinct CT accounts of any role assigned...

System: CT

CT accounts

System: CT

client

SELECT COUNT(DISTINCT a.id) AS client_count FROM public.accounts a JOIN public.user_analytics ua ON ua.user_id = a.id WHERE a.campaign_id IS NOT NULL AND NULLIF(ua.came_from_domain, '') IS NOT NULL

SELECT
  COUNT(DISTINCT a.id) AS client_count
FROM public.accounts AS a
JOIN public.user_analytics AS ua
  ON ua.user_id = a.id
WHERE
  NOT a.campaign_id IS NULL AND NOT NULLIF(ua.came_from_domain, '') IS NULL

Known referral domain means came_from_domain is populated and non-empty.

Campaign assignment means the account has a non-null campaign_id.

List those 43 accounts with their campaign and referral domain.

How does this compare with the count of all campaign-assigned CT accounts, i.e. how many have no known referral domain?

This is a single aggregate figure with no breakdown by campaign or role, so concentration cannot be assessed from this result.

How many distinct CT accounts of any role assigned to a campaign and with a known web referral domain are there? Return client_count, including zero if none qualify.

Counts each distinct account id once, using the accounts table.

Joins each account to its row in user_analytics by matching user_id to the account id, so only accounts with a matching analytics row are kept.

Keeps only accounts where campaign_id is filled in (excludes accounts with no campaign assigned).

Keeps only rows where came_from_domain is non-empty: NULLIF turns an empty string into null, and the IS NOT NULL check excludes null results, so blank or missing domains are dropped.

Summary: Counts distinct accounts that have a campaign assigned and a non-empty referral domain in their analytics record, returning zero if none qualify.


3 distinct professional CT partner accounts have both paid and unpaid monthly affiliate statements.

How many distinct professional CT partner accounts...

System: CT

partner

System: CT

accounts

System: CT

client

SELECT COUNT(DISTINCT s.affiliate_id) AS client_count FROM public.affiliate_commission_statements s JOIN public.accounts a ON a.id = s.affiliate_id WHERE a.role IN ('Affiliate','AffiliateManager','Partner') GROUP BY s.affiliate_id HAVING BOOL_OR(s.paid_at IS NOT NULL) AND BOOL_OR(s.paid_at IS NULL)

SELECT
  COUNT(DISTINCT s.affiliate_id) AS client_count
FROM public.affiliate_commission_statements AS s
JOIN public.accounts AS a
  ON a.id = s.affiliate_id
WHERE
  a.role IN ('Affiliate', 'AffiliateManager', 'Partner')
GROUP BY
  s.affiliate_id
HAVING
  BOOL_OR(NOT s.paid_at IS NULL) AND BOOL_OR(s.paid_at IS NULL)

'Professional CT partner accounts' was interpreted as accounts with role in ('Affiliate', 'AffiliateManager', 'Partner')

'Unpaid' means paid_at is null on the statement, with no regard to statement due date or age

List the 3 affiliate accounts with both paid and unpaid statements, with their statement counts and unpaid amounts

How far back do the unpaid statements for these accounts date, and what is the total outstanding?

Are there other partner accounts with only unpaid statements that were excluded by the both-conditions requirement?

Each row returns client_count = 1 because the query groups by affiliate_id before counting; the true total is the row count, i.e. 3 affiliates.

All 3 rows are shown (rows returned matches the sample), so this is the complete set, not a capped or partial result.

How many distinct professional CT partner accounts with both paid and unpaid monthly affiliate statements are there? Return client_count, including zero if none qualify.

Reads rows from affiliate_commission_statements and joins each to accounts on accounts.id = statements.affiliate_id, keeping only matching pairs.

Keeps only statements whose linked account has role 'Affiliate', 'AffiliateManager', or 'Partner' — accounts with any other role are excluded.

Within each affiliate, checks that at least one statement has a non-empty paid_at (paid) and at least one has an empty paid_at (unpaid); only affiliates meeting both conditions survive.

Counts the distinct affiliate_ids that survived; because the count is wrapped around the whole result, it returns 0 when no affiliate qualifies.

Summary: Count how many distinct affiliate accounts have at least one paid and one unpaid commission statement, then return that count (which will be 0 if none qualify).


System: CT

client

System: CT

sell currency

DECLARED (onboarding) sell currencies — the currencies the client SAID at sign-up they wanted to sell. NOT actually-traded (that is trade_bookings.sell_currency/buy_currency) and NOT a residence cohort. An ARRAY (text[]): test membership with `'<CODE>' = ANY(clients.sell_currencies)`; there is NO singular sell_currency column on clients and a scalar comparison fails validation. Declared intent needs NO trade — a client who never traded still has one — so never add a trade-existence predicate to a declared-intent cohort. A generic 'declared/intended to trade <CODE>' is EITHER side: OR this with ct.clients.buy_currencies; '<CODE> book' is the TRADED cohort, a different lens.

System: CT

declared sell currencies

```json
{
  "sql": "",
  "explanation": "Cannot generate: the provided schema lists no columns, and the request requires ct.client_360 and fields (trade sell currency, declared sell currencies) that are not available in the schema context.",
  "confidence": "uncertain",
  "warnings": ["No column met

How many distinct CT client records who booked a non-deleted, non-closed trade in a sell currency absent from their declared sell currencies are there? Return client_count, including zero if none qualify.


15 ordinary CT user accounts have completed registration but are missing or blank in at least one of first name, last name, or telephone.

How many distinct ordinary CT user accounts with c...

System: CT

accounts

Identity placeholder — NEVER select the physical column in SQL (the validator rejects it): project `NULL AS first_name`; the server fills real values post-execution keyed on user_id.

System: CT

first-name

Identity placeholder — NEVER select the physical column in SQL (the validator rejects it): project `NULL AS last_name`; the server fills real values post-execution keyed on user_id.

System: CT

last-name

Identity placeholder — NEVER select the physical column in SQL (the validator rejects it): project `NULL AS telephone`; the server fills real values post-execution keyed on user_id.

System: CT

telephone

System: CT

client

SELECT COUNT(*) AS client_count, NULL AS phone FROM public.accounts AS a JOIN public.clients AS c ON c.user_id = a.id WHERE a.role = 'User' AND NOT a.skip_commission_calculations IS TRUE AND NOT c.completed_registration_at IS NULL AND (a.first_name IS NULL OR a.first_name = '' OR a.last_name IS NULL OR a.last_name = '' OR a.telephone IS NULL OR a.telephone = '')

SELECT
  COUNT(*) AS client_count,
  NULL AS phone
FROM public.accounts AS a
JOIN public.clients AS c
  ON c.user_id = a.id
WHERE
  a.role = 'User'
  AND NOT a.skip_commission_calculations IS TRUE
  AND NOT c.completed_registration_at IS NULL
  AND (
    a.first_name IS NULL
    OR a.first_name = ''
    OR a.last_name IS NULL
    OR a.last_name = ''
    OR a.telephone IS NULL
    OR a.telephone = ''
  )

'Ordinary' = role 'User' and excluding accounts where skip_commission_calculations is true

'Complete registration' = completed_registration_at is not null

Reading this as the registration-form funnel — started the signup wizard vs finished it (clients.completed_registration_at). If you meant activation (verified & ready to trade), say so.

List the 15 accounts with their user ids and which specific fields are missing.

Which of these 15 accounts have been active or funded recently?

The SQL counts accounts, not necessarily distinct clients; if a user id repeats, account and client counts could differ.

This is an OR condition, so the 15 includes accounts missing any one of the three fields, not all of them.

How many distinct ordinary CT user accounts with complete registration but at least one missing or blank first-name, last-name, or telephone field are there? Return client_count, including zero if none qualify.

Join public.accounts to public.clients by matching clients.user_id to accounts.id.

Keep only rows where the account's role is 'User'.

Exclude rows where skip_computations... specifically: require that skip_commission_calculations is not set to true.

Require that completed_registration_at is not null, i.e. registration timestamp is filled in.

Keep rows where at least one of first_name, last_name, or telephone is null or an empty string.

Count the qualifying rows and return that count as client_count; the phone column is always null.

Summary: Count rows that join accounts to clients, keep only regular users with commission calculations not skipped and registration completed, and have at least one null or blank name or telephone field.


System: PD

people

System: PD

owner

System: PD

organization

System: CT

client

SELECT COUNT(DISTINCT a.id) AS client_count FROM public.accounts a

SELECT c.user_id, COUNT(DISTINCT pe.id)::numeric AS client_count FROM ct.client_360 c LEFT JOIN pipedrive.persons_enriched pe ON pe.ct_id = c.user_id LEFT JOIN pipedrive.organizations o ON o.id = pe.org_id WHERE pe.owner_id IS NOT NULL AND o.owner_id IS NOT NULL AND pe.owner_id <> o.owner_id GROUP BY 1

How many distinct Pipedrive people whose owner differs from the owner of their organization are there? Return client_count, including zero if none qualify.


2 distinct private clients have a rejected registration status but an existing broker verification timestamp.

How many distinct private CT client records whose ...

System: CT

client

System: CT

broker

SELECT COUNT(DISTINCT c.user_id) AS client_count FROM public.clients c JOIN public.accounts a ON a.id = c.user_id WHERE c.type = 'PersonalAccount' AND c.status = 'rejected' AND EXISTS (SELECT 1 FROM public.broker_accounts ba WHERE ba.user_id = c.user_id AND ba.verified_at IS NOT NULL)

SELECT
  COUNT(DISTINCT c.user_id) AS client_count
FROM public.clients AS c
JOIN public.accounts AS a
  ON a.id = c.user_id
WHERE
  c.type = 'PersonalAccount'
  AND c.status = 'rejected'
  AND EXISTS(
    SELECT
      1
    FROM public.broker_accounts AS ba
    WHERE
      ba.user_id = c.user_id AND NOT ba.verified_at IS NULL
  )

'Private CT clients' interpreted as clients with type = 'PersonalAccount'

'Broker verification timestamp exists' means at least one broker account row with verified_at populated

Which clients are these — list their user IDs and registration dates?

How do these clients' account statuses compare with their broker verification dates?

Rejected sign-ups with a completed broker verification are unusual — these two may indicate status updates that lag or override verification, or a workflow gap worth reviewing.

activation-definition activation-definition-gold onboarding-duration churn-tier-definitions declared-currency-intent trade-existence-default-booked settlement-is-ct-trade-lifecycle client-type-sti-classes

How many distinct private CT client records whose registration status is rejected but whose broker verification timestamp exists are there? Return client_count, including zero if none qualify.

Joins clients to accounts, matching accounts.id to clients.user_id, so only clients with a matching account row are kept.

Keeps only rows where clients.type = 'PersonalAccount' and clients.status = 'rejected'.

Uses an existence check on broker_accounts: at least one row for that user must have verified_at IS NOT NULL (a timestamp present).

Counts distinct clients.user_id values and returns the result as client_count (zero if none qualify).

Summary: Counts distinct users who have a PersonalAccount client record with status 'rejected' and a matching account row, and also have at least one broker_accounts row with a verified_at timestamp.


System: PD

people

System: PD

stage

System: CT

client

```json
{
  "sql": "",
  "explanation": "The requested cohort (Pipedrive people with a lead qualification date and no Negotiation-stage deal) is defined entirely by Pipedrive/CRM fields that do not exist on this connection, so no CT-side query can produce it.",
  "confidence": "uncertain",
  "warnin

```json
{
  "sql": "",
  "explanation": "Cannot generate: the schema lists no columns for any table, and neither 'lead qualification date' nor 'Negotiation' stage fields can be reliably mapped.",
  "confidence": "uncertain",
  "warnings": ["The provided schema contains tables with empty column lists

How many distinct Pipedrive people who have a lead qualification date but no deal in the Negotiation stage are there? Return client_count, including zero if none qualify.


All sampled user rows show 0 Pipedrive people with a cross-organisation deal mismatch, but the sample covers only the first 12 of 45 rows.

Keyed merge and authoritative-source checks.

Keys, merge grain, and source membership were checked.

How many distinct Pipedrive people with a deal ass...

System: PD

people

System: PD

organization

System: CT

client

Query times are separate. Source refresh time is unknown unless supplied.

SELECT c.user_id, COUNT(DISTINCT pe.id) FILTER (WHERE d.org_id IS DISTINCT FROM pe.org_id) AS client_count FROM ct.client_360 c LEFT JOIN pipedrive.persons_enriched pe ON pe.ct_id = c.user_id LEFT JOIN pipedrive.deals d ON d.person_id = pe.id GROUP BY 1

SELECT a.id AS user_id FROM public.accounts AS a LIMIT 10000

CT-realized and Pipedrive pipeline measures are kept separate; not summed across sources.

Mismatch judged solely on org_id differing between the deal and the person record, including nulls on either side (IS DISTINCT FROM).

Only Pipedrive persons linked to a client_360 record via ct_id are counted; unmatched persons are excluded.

Which user_id rows have a client_count above zero, and what is each count?

Each row counts distinct persons whose deal's org_id differs from their person org_id, or 0 where there is no match; the first 12 rows all show 0.

With 45 rows returned and only 12 sampled, the result cannot be summed or characterised beyond the rows shown.

How many distinct Pipedrive people with a deal assigned to a different organization from their person record are there? Return client_count, including zero if none qualify.

[Gold / Pipedrive] Start from ct.client_360, which gives one row per user_id.

[Gold / Pipedrive] Attach matching info from pipedrive.persons_enriched via ct_id = user_id, keeping user rows even when no person matches.

[Gold / Pipedrive] Attach matching info from pipedrive.deals via person_id = person id, keeping person rows even when no deal matches.

[Gold / Pipedrive] For each user, count distinct person ids, but only where the deal's org_id is different from the person's org_id (rows with no deal, or with equal or null-mismatched orgs, are excluded by that conditi…

[CT Ledger] Take ids from public.accounts, renamed as user_id, capped at the first 10,000 rows.

[Merged] The two sources are joined per user_id so each account id keeps its client_count, or lacks one when the Pipedrive half had no row for that user.

Summary: The Gold/Pipedrive half counts, per user, how many distinct Pipedrive people have a deal whose organization differs from the person's own organization; the CT Ledger half supplies a list of account ids, and the two are merged per user so users with no qualifying people still show up with a count of zero or null as the…


System: PD

people

System: CT

client

SELECT c.user_id, COUNT(DISTINCT n.person_id) AS client_count FROM ct.client_360 c JOIN pipedrive.notes n ON n.person_id = c.person_id AND n.active = true AND (n.deal_id IS NULL) GROUP BY c.user_id

How many distinct Pipedrive people with an active note pinned to the person but not pinned to a deal are there? Return client_count, including zero if none qualify.


54 distinct Pipedrive people have at least one activity whose due date precedes its creation date.

No complete question-to-answer semantic oracle was run.

SQL checks do not prove the whole question interpretation.

How many distinct Pipedrive people with an activit...

System: PD

people

System: PD

activity

System: PD

due date

System: CT

client

Simple single-table query with basic aggregation

High confidence (100%) — clear time period, simple query

SELECT COUNT(DISTINCT a.person_id) AS client_count FROM pipedrive.activities a WHERE a.person_id IS NOT NULL AND a.due_date IS NOT NULL AND a.add_time IS NOT NULL AND a.due_date::date < a.add_time::date

SELECT
  COUNT(DISTINCT a.person_id) AS client_count
FROM pipedrive.activities AS a
WHERE
  NOT a.person_id IS NULL
  AND NOT a.due_date IS NULL
  AND NOT a.add_time IS NULL
  AND CAST(a.due_date AS DATE) < CAST(a.add_time AS DATE)

Counts people linked to any activity; activities with no person attached are excluded.

List those 54 people with the number of affected activities each.

Which users or pipelines created these backdated activities?

How many total activities have a due date before their creation date?

The count is of people, not activities, so the underlying number of affected activities could be higher.

The comparison is date-level (due_date::date vs add_time::date), so same-day backdated times are not counted.

How many distinct Pipedrive people with an activity whose due date precedes its creation date are there? Return client_count, including zero if none qualify.

Keeps only rows where person_id, due_date, and add_time are all filled in (rows missing any of these are excluded).

Keeps only rows where the due date (as a calendar date) is earlier than the creation date (as a calendar date).

Counts the distinct person_id values among those rows and names the result client_count.

Summary: Counts distinct people in the activities table who have an activity due before the date it was created, returning zero if none.


System: PD

people

System: CT

client

SELECT CAST(0 AS BIGINT) AS client_count LIMIT 10000

SELECT c.user_id FROM ct.client_360 AS c JOIN pipedrive.deals AS d ON d.person_id = c.person_id WHERE d.status = 'open' AND d.expected_close_date < CAST('2026-09-01' AS DATE) AND d.close_time IS NULL GROUP BY c.user_id LIMIT 10000

How many distinct Pipedrive people with an open deal expected to close before 1 September 2026 but with no actual close timestamp are there? Return client_count, including zero if none qualify.


System: PD

people

System: PD

organization

System: PD

employee count

System: PD

people count

System: CT

client

```json
{
  "sql": "",
  "explanation": "The qualifying condition (Pipedrive people whose organization has a known positive employee count but an unknown people count) is defined entirely by Pipedrive-side organization attributes, and this connection has no Pipedrive tables or columns to evaluate it

How many distinct Pipedrive people whose organization has a known positive employee count but an unknown people count are there? Return client_count, including zero if none qualify.


System: PD

people

System: PD

organization

System: PD

company introducer

System: CT

client

SELECT CAST(NULL AS BIGINT) AS client_count LIMIT 10000

SELECT COUNT(DISTINCT pe.id)::int AS client_count FROM pipedrive.persons_enriched pe JOIN pipedrive.organizations o ON o.id = pe.org_id WHERE o.cf_company_introducer IS NOT NULL AND o.cf_company_introducer <> o.id AND EXISTS (SELECT 1 FROM pipedrive.organizations intro WHERE intro.id = o.cf_company_introducer)

How many distinct Pipedrive people at an organization whose company introducer is another known organization are there? Return client_count, including zero if none qualify.


64 distinct Pipedrive people match, but the query actually counts all persons — no email/phone preference filter was applied.

How many distinct Pipedrive people whose contact p...

System: PD

people

System: CT

phone

System: CT

client

SELECT COUNT(DISTINCT id) AS client_count, NULL AS email, NULL AS phone FROM pipedrive.persons

Query as written includes all Pipedrive persons regardless of contact preference — the intended email-not-phone filter is not present in the SQL

Rerun with a filter on the contact preference array containing email but not phone to get the true count

List the Pipedrive people whose contact preference includes email but not phone

The SQL counts every distinct person in pipedrive.persons with no filtering on contact preference, so the figure of 64 is the total person count, not the email-without-phone subset.

A corrected query would filter the contact preference array for containing email and excluding phone.

How many distinct Pipedrive people whose contact preference array includes email but not phone are there? Return client_count, including zero if none qualify.

FROM pipedrive.persons: reads every row of the persons table with no filtering — the email-only / no-phone condition from the question is not applied anywhere.

COUNT(DISTINCT id): counts each unique person ID once.

Two empty placeholder columns labeled email and phone are returned as blank values alongside the count.

Summary: The query counts the total number of distinct person IDs in the Pipedrive persons table, ignoring the email/phone preference filters entirely.


System: PD

people

Declared intended trading frequency captured at onboarding (synced onward to Pipedrive).

System: CT

trade frequency

System: CT

client

```json
{
  "sql": "",
  "explanation": "The schema context lists table names but no columns (no trade-frequency field or user_id linkage is defined for pipedrive.persons or ct.client_360), so a correct query cannot be built.",
  "confidence": "uncertain",
  "warnings": ["No column metadata availabl

How many distinct Pipedrive people who declared more than one trade frequency are there? Return client_count, including zero if none qualify.


System: PD

people

System: PD

organization

System: CT

client

```json
{
  "sql": "",
  "explanation": "The schema contains no booking or hedging policy column on pipedrive.organizations (or any table), so this question cannot be translated without inventing a column.",
  "confidence": "uncertain",
  "warnings": [
    "organizations has exactly the listed colum

How many distinct Pipedrive people whose organization declares more than one booking or hedging policy are there? Return client_count, including zero if none qualify.


System: PD

people

System: PD

organization

System: PD

LinkedIn

System: PD

website

System: CT

client

SELECT COUNT(DISTINCT a.id) AS client_count FROM public.accounts a JOIN public.clients c ON c.user_id = a.id

SELECT COUNT(DISTINCT pe.id) AS client_count FROM persons_enriched pe JOIN organizations o ON o.id = pe.org_id WHERE o.linkedin IS NOT NULL AND (o.website IS NULL OR o.website = '')

How many distinct Pipedrive people at an organization with a LinkedIn page and no website are there? Return client_count, including zero if none qualify.


43 distinct Pipedrive people have an activity assigned to someone other than the owner of its deal.

System: PD

people

System: PD

activity

System: PD

owner

System: CT

client

SELECT COUNT(DISTINCT a.person_id) AS client_count FROM pipedrive.activities a JOIN pipedrive.deals d ON d.id = a.deal_id WHERE a.person_id IS NOT NULL AND a.assigned_to_user_id IS NOT NULL AND d.owner_id IS NOT NULL AND a.assigned_to_user_id <> d.owner_id

SELECT
  COUNT(DISTINCT a.person_id) AS client_count
FROM pipedrive.activities AS a
JOIN pipedrive.deals AS d
  ON d.id = a.deal_id
WHERE
  NOT a.person_id IS NULL
  AND NOT a.assigned_to_user_id IS NULL
  AND NOT d.owner_id IS NULL
  AND a.assigned_to_user_id <> d.owner_id

Counts only activities joined to a deal (deal_id present), excluding activities with no deal link.

Excludes rows where the assignee, deal owner or person is null rather than treating them as non-matching.

List the 43 people and their deals where the activity assignee differs from the deal owner.

Which users are most often assigned activities on deals they do not own?

This counts only activities linked to a deal with a known owner and a non-null assignee and person, so activities without those links are excluded from scope.

How many distinct Pipedrive people with an activity assigned to someone other than the owner of its deal are there? Return client_count, including zero if none qualify.

Join each activity to its matching deal on the deal ID.

Keep only rows where the activity's person, the activity's assigned user, and the deal's owner are all filled in.

Exclude rows where the activity's assigned user is the same as the deal's owner, keeping only the mismatches.

Count the distinct person IDs across those rows and return the number as client_count.

Summary: Count the distinct non-null person IDs on activities whose assigned user differs from the owner of the activity's deal.


System: PD

people

System: PD

owner

System: CT

client

SELECT COUNT(DISTINCT a.id)::bigint AS client_count FROM public.accounts a JOIN public.clients c ON c.user_id = a.id WHERE a.role = 'User' AND NOT a.skip_commission_calculations IS TRUE

SELECT COUNT(DISTINCT d.person_id) AS client_count FROM pipedrive.deals d JOIN pipedrive.notes n ON n.deal_id = d.id WHERE d.owner_id IS NOT NULL AND n.user_id IS NOT NULL AND n.user_id <> d.owner_id

How many distinct Pipedrive people with an active deal note authored by someone other than the deal owner are there? Return client_count, including zero if none qualify.


System: PD

people

Client sign-up / registration timestamp.

System: CT

signup date

Onboarding/client dimension keyed by user_id (= accounts.id). Declared (not traded) currencies live here.

System: CT

client

```json
{
  "sql": "",
  "explanation": "This connection has no Pipedrive tables, so 'non-employee' marking and 'lead qualification date' cannot be filtered here — only NULL placeholders could be projected, and the count itself is uncomputable on the CT leg.",
  "confidence": "uncertain",
  "warning

How many distinct Pipedrive people explicitly marked as non-employees whose lead qualification date follows their signup date are there? Return client_count, including zero if none qualify.


System: PD

people

System: PD

organization

System: PD

wallet-share

System: CT

System: CT

System: PD

System: both

System: PD

value

System: CT

client

churn-tier-definitions declared-currency-intent activation-definition-gold client-type-sti-classes trade-existence-gold-booked

```json
{
  "sql": "",
  "explanation": "Service level and wallet-share are Pipedrive-only fields with no counterpart in the CT schema, so this leg cannot evaluate the cohort predicate.",
  "confidence": "uncertain",
  "warnings": ["No Pipedrive/CRM tables exist on this connection and no CT column e

How many distinct Pipedrive people at an organization with a known service level but an unknown wallet-share value are there? Return client_count, including zero if none qualify.


System: PD

people

System: PD

organization

System: CT

client

SELECT a.id AS user_id, COUNT(*) AS client_count FROM public.accounts a WHERE 1 = 0 GROUP BY a.id

SELECT COUNT(DISTINCT pe.id) AS client_count FROM pipedrive.persons_enriched pe JOIN pipedrive.organizations o ON o.id = pe.org_id WHERE ((CASE WHEN o.name ILIKE '%sap%' THEN 1 ELSE 0 END) + (CASE WHEN o.name ILIKE '%oracle%' THEN 1 ELSE 0 END) + (CASE WHEN o.name ILIKE '%netsuite%' THEN 1 ELSE 0 END) + (CASE WHEN o.name ILIKE '%dynamics%' THEN 1 ELSE 0 END) + (CASE WHEN o.name ILIKE '%workday%' THEN 1 ELSE 0 END) + (CASE WHEN o.name ILIKE '%infor%' THEN 1 ELSE 0 END) + (CASE WHEN o.name ILIKE '%epicor%' THEN 1 ELSE 0 END) + (CASE WHEN o.name ILIKE '%sage%' THEN 1 ELSE 0 END) + (CASE WHEN o.name ILIKE '%odoo%' THEN 1 ELSE 0 END) + (CASE WHEN o.name ILIKE '%microsoft%' THEN 1 ELSE 0 END)) >= 2

How many distinct Pipedrive people whose organization names at least two ERP systems are there? Return client_count, including zero if none qualify.


System: PD

people

System: PD

stage

System: CT

client

```json
{
  "sql": "",
  "explanation": "The provided schema lists table names but no columns, so there is no declared stage-change or creation timestamp column on deals to compare, and no user_id key is visible on client_360 or persons.",
  "confidence": "uncertain",
  "warnings": [
    "Cannot ver

How many distinct Pipedrive people with a deal whose stage-change timestamp predates its creation timestamp are there? Return client_count, including zero if none qualify.


System: PD

people

System: PD

activity

System: PD

duration

System: PD

due time

System: CT

client

Sql: The generated SQL could not complete the requested query. Rephrase to only request data you have access to

SELECT COUNT(DISTINCT a.person_id)::int AS client_count FROM activities a WHERE a.person_id IS NOT NULL AND a.duration IS NOT NULL AND (a.due_time IS NULL OR a.due_time = '')

SELECT
  CAST(COUNT(DISTINCT a.person_id) AS INT) AS client_count
FROM activities AS a
WHERE
  NOT a.person_id IS NULL
  AND NOT a.duration IS NULL
  AND (
    a.due_time IS NULL OR a.due_time = ''
  )

How many distinct Pipedrive people with an activity that has a duration but no due time are there? Return client_count, including zero if none qualify.

The generated query couldn't be validated. This might be due to security restrictions or invalid SQL.


System: PD

people

System: PD

organization

System: CT

client-type

System: CT

client

```json
{
  "sql": "",
  "explanation": "The schema provides no column definitions, and neither pipedrive.organizations nor ct.client_360 exposes a client-type tag or org-tag relation I can reliably query.",
  "confidence": "uncertain",
  "warnings": ["No table in the provided schema lists columns (

How many distinct Pipedrive people at an organization with more than one client-type tag are there? Return client_count, including zero if none qualify.


List every distinct CT accounts of any role whose ...

accounts IS the canonical CT user table: accounts.id EQUALS user_id. Carries relationship_manager_id and latest_pipedrive_activity_at. A REFERRER is an account referenced by another account's affiliate_id (refer-and-earn referrer when referrer.role='User'; 'referrer(s)' is a CT concept, NEVER the Pipedrive cf_referrer custom field — same suppression as 'partners'). NAME EXPOSURE (ruling 2026-07-08): individual first/last name and company name MAY be SHOWN in result rows to anyone with vault access (the vault boundary IS the authorization) — they are filled server-side post-execution as a display column (client_name / first_name / last_name / company_name placeholders), NEVER read via model-generated SQL (the CT-leg gate rejects a physical read; the model projects `NULL AS <col>`). CONTACT PII stays intentionally NOT exposed: email, telephone/phone and IPs are never shown in results (they remain WHERE-only filters where already allowed).

System: CT

CT accounts

The trade's PAYMENT/LIQUIDITY PARTNER — CT calls this the BROKER (live names include Corpay, Corpay Offline, Currencycloud, Clear Treasury, Moneycorp, Verto, iBan First, Central FX). Resolve the partner NAME by joining: JOIN public.broker_accounts ba ON ba.id = tb.broker_account_id JOIN public.brokers b ON b.id = ba.broker_id, then use b.name as the partner dimension (GROUP BY b.name for a by-partner breakdown; every trade_bookings row carries broker_account_id). NEVER use trade_bookings.platform for a partner/provider/broker breakdown — platform is the booking CHANNEL (web/ios/system/nexus), not a partner — and never alias platform AS payment_partner.

System: CT

broker

System: CT

registration date

System: CT

System: PD

person ID

0 matching rows — a filter likely did not bind; verify filters. High confidence (85%) — moderate complexity

SELECT a.id AS user_id, MIN(ba.verified_at) AS first_verified_at, c.completed_registration_at FROM public.accounts AS a JOIN public.clients AS c ON c.user_id = a.id JOIN public.broker_accounts AS ba ON ba.user_id = a.id WHERE NOT c.completed_registration_at IS NULL AND NOT ba.verified_at IS NULL GROUP BY a.id, c.completed_registration_at HAVING MIN(ba.verified_at) > c.completed_registration_at ORDER BY 1 ASC

activation-definition activation-definition-gold onboarding-duration churn-tier-definitions trade-existence-default-booked settlement-is-ct-trade-lifecycle trade-existence-gold-booked

List every distinct CT accounts of any role whose earliest verified broker account date is after their completed registration date. Return only user_id, in ascending order; use the person ID for a Pipedrive-only person.


System: CT

accounts

System: CT

System: PD

person ID

Semantic: The query could not preserve the requested meaning or scope. Try using specific metric names like 'MRR' or 'revenue'

activation-definition activation-definition-gold onboarding-duration churn-tier-definitions trade-existence-gold-booked

```json
{
  "sql": "",
  "explanation": "Cannot generate: the provided schema lists the accounts table with NO columns, so there is no way to know which column stores the marketing-email opt-in flag or the registration-completion status, and inventing them would be a guess.",
  "confidence": "uncert

```json
{
  "sql": "",
  "explanation": "The provided schema lists no columns for any table, and the curated knowledge does not define which columns in ct.accounts capture marketing-email opt-in, registration completeness, or 'ordinary' account type, so a correct SELECT cannot be generated.",
  "con

List every distinct ordinary CT user accounts opted in to marketing emails whose registration is still incomplete. Return only user_id, in ascending order; use the person ID for a Pipedrive-only person.

I couldn't understand that query. Try rephrasing it or using simpler terms.


No CT accounts meet the condition: the distinct client count whose earliest verified broker account date falls after completed registration is 0.

For exactly the CT accounts of any role whose earl...

System: CT

CT accounts

System: CT

broker

System: CT

registration date

System: CT

client

SELECT COUNT(*) AS client_count FROM (SELECT a.id, c.completed_registration_at FROM public.accounts AS a JOIN public.clients AS c ON c.user_id = a.id JOIN public.broker_accounts AS ba ON ba.user_id = a.id WHERE NOT c.completed_registration_at IS NULL AND NOT ba.verified_at IS NULL GROUP BY a.id, c.completed_registration_at HAVING MIN(ba.verified_at) > c.completed_registration_at) AS _first_event_cohort

SELECT
  COUNT(*) AS client_count
FROM (
  SELECT
    a.id,
    c.completed_registration_at
  FROM public.accounts AS a
  JOIN public.clients AS c
    ON c.user_id = a.id
  JOIN public.broker_accounts AS ba
    ON ba.user_id = a.id
  WHERE
    NOT c.completed_registration_at IS NULL AND NOT ba.verified_at IS NULL
  GROUP BY
    a.id,
    c.completed_registration_at
  HAVING
    MIN(ba.verified_at) > c.completed_registration_at
) AS _first_event_cohort

'Verified' means broker_accounts.verified_at is non-null, and only broker accounts with a non-null verified_at were considered when taking the earliest date.

Clients with a null completed_registration_at were excluded from the cohort entirely.

The count is genuinely zero rather than missing — the cohort query ran and returned a row with client_count = 0, so every client with both a completed registration and a verified broker account had their first verification on or before registration.

For exactly the CT accounts of any role whose earliest verified broker account date is after their completed registration date in the first checked result, return their distinct count as client_count. Keep that membership and return zero if it is empty.

Join accounts to clients on the client's user_id matching the account id, and join broker_accounts the same way.

Keep only rows where completed_registration_at and verified_at are both non-null.

Group by account id and registration date; keep a group only if its earliest verified_at is later than the completed registration date.

The outer part counts those matching rows and returns the count as client_count (zero if none match).

Summary: Count the distinct users who have a client record with a completed registration date, at least one verified broker account, and whose earliest broker verification happened after registration.


Show the same checked IDs for the CT accounts of a...

System: CT

CT accounts

System: CT

broker

System: CT

registration date

System: CT

SELECT a.id AS user_id FROM public.accounts AS a JOIN public.clients AS c ON c.user_id = a.id JOIN public.broker_accounts AS ba ON ba.user_id = a.id WHERE NOT c.completed_registration_at IS NULL AND NOT ba.verified_at IS NULL GROUP BY a.id, c.completed_registration_at HAVING MIN(ba.verified_at) > c.completed_registration_at ORDER BY 1 DESC NULLS LAST

Show the same checked IDs for the CT accounts of any role whose earliest verified broker account date is after their completed registration date from the first result, this time in descending user_id order. Keep every member and show only user_id.


System: CT

accounts

System: CT

client

```json
{
  "sql": "",
  "explanation": "The requested filters (marketing-email opt-in status and registration-completeness) have no known columns in the provided schema, and ct.client_360 is not listed with any columns, so the membership condition cannot be expressed.",
  "confidence": "uncertain",

For exactly the ordinary CT user accounts opted in to marketing emails whose registration is still incomplete in the first checked result, return their distinct count as client_count. Keep that membership and return zero if it is empty.


System: CT

accounts

System: CT

```json
{
  "sql": "",
  "explanation": "The request depends on a prior result whose filters (marketing-email opt-in, incomplete registration) cannot be mapped to any documented columns — the provided schema lists table names with no columns, and the curated knowledge confirms no such flags exist on

Show the same checked IDs for the ordinary CT user accounts opted in to marketing emails whose registration is still incomplete from the first result, this time in descending user_id order. Keep every member and show only user_id.


Zero clients have an earliest verified broker account dated after their completed registration date.

Keep the CT accounts of any role whose earliest ve...

System: CT

CT accounts

System: CT

broker

System: CT

registration date

System: CT

client

SELECT COUNT(*) AS client_count FROM (SELECT a.id AS user_id FROM public.accounts AS a JOIN public.clients AS c ON c.user_id = a.id JOIN public.broker_accounts AS ba ON ba.user_id = a.id WHERE NOT c.completed_registration_at IS NULL AND NOT ba.verified_at IS NULL GROUP BY a.id, c.completed_registration_at HAVING MIN(ba.verified_at) > c.completed_registration_at) AS members

SELECT
  COUNT(*) AS client_count
FROM (
  SELECT
    a.id AS user_id
  FROM public.accounts AS a
  JOIN public.clients AS c
    ON c.user_id = a.id
  JOIN public.broker_accounts AS ba
    ON ba.user_id = a.id
  WHERE
    NOT c.completed_registration_at IS NULL AND NOT ba.verified_at IS NULL
  GROUP BY
    a.id,
    c.completed_registration_at
  HAVING
    MIN(ba.verified_at) > c.completed_registration_at
) AS members

Membership defined as accounts having a verified broker account whose earliest verified_at is strictly after completed_registration_at

Excludes clients with no completed registration date and broker accounts with no verified date

No clients met the membership condition, so the resulting set is empty and the derived client_count is zero.

Keep the CT accounts of any role whose earliest verified broker account date is after their completed registration date membership from the third result and count those distinct IDs as client_count. An empty result counts as zero.

Join accounts, clients, and broker_accounts by matching each client's and broker account's user_id to the account's id.

Keep only rows where the client has a completed_registration_at date and the broker account has a verified_at date (rows missing either are excluded).

Group everything per account id together with its registration date.

Keep only groups whose earliest (minimum) verified_at is strictly later than that user's completed_registration_at.

Count how many such users there are; if none qualify, the count is zero.

Summary: Count users who have a client record, at least one verified broker account, and whose earliest broker verification date is later than their completed registration date.


System: CT

accounts

System: CT

client

```json
{
  "sql": "",
  "explanation": "Cannot generate: no column information is available for any table (all column lists are empty), ct.client_360 itself is not in the provided schema, and the question's filters (marketing-email opt-in, incomplete registration, 'third result' membership) referen

Keep the ordinary CT user accounts opted in to marketing emails whose registration is still incomplete membership from the third result and count those distinct IDs as client_count. An empty result counts as zero.


System: CT

CT accounts

System: CT

broker

System: CT

System: PD

person ID

churn-tier-definitions trade-existence-default-booked settlement-is-ct-trade-lifecycle activation-definition-gold trade-existence-gold-booked

```json
{
  "sql": "",
  "explanation": "Cannot generate: the request requires ct.client_360 and broker-account verification-status fields, but the provided schema lists no columns for any table (and no ct.client_360 at all), so 'previously verified broker account now marked outdated' cannot be mapp

List every distinct CT accounts of any role with a previously verified broker account now marked outdated. Return only user_id, in ascending order; use the person ID for a Pipedrive-only person.


System: CT

CT accounts

System: CT

broker

System: CT

System: PD

person ID

SELECT a.id AS user_id FROM public.accounts AS a WHERE EXISTS(SELECT 1 FROM public.broker_accounts AS ban WHERE ban.user_id = a.id AND NOT ban.notified_at IS NULL) AND NOT EXISTS(SELECT 1 FROM public.broker_accounts AS bav WHERE bav.user_id = a.id AND NOT bav.verified_at IS NULL) ORDER BY 1 LIMIT 10000

SELECT c.user_id FROM ct.client_360 AS c WHERE c.notified_broker_accounts_count > 0 AND COALESCE(c.verified_broker_accounts_count, 0) = 0 GROUP BY c.user_id ORDER BY c.user_id ASC LIMIT 10000

List every distinct CT accounts of any role with a notified broker account but no broker account that has ever been verified. Return only user_id, in ascending order; use the person ID for a Pipedrive-only person.


System: CT

CT accounts

System: CT

broker

System: CT

client

```json
{
  "sql": "",
  "explanation": "The provided schema contains no ct.client_360 view or column-level details for broker account verification status, so the requested cohort cannot be expressed.",
  "confidence": "uncertain",
  "warnings": ["Schema context lists table names only with no column

For exactly the CT accounts of any role with a previously verified broker account now marked outdated in the first checked result, return their distinct count as client_count. Keep that membership and return zero if it is empty.


System: CT

CT accounts

System: CT

broker

System: CT

client

```json
{
  "sql": "",
  "explanation": "The request requires ct.client_360 and pipedrive.* with broker-account verification logic, but the provided schema lists no columns for any table and no ct.client_360 or pipedrive tables exist in it.",
  "confidence": "uncertain",
  "warnings": ["Schema conta

For exactly the CT accounts of any role with a notified broker account but no broker account that has ever been verified in the first checked result, return their distinct count as client_count. Keep that membership and return zero if it is empty.


System: CT

CT accounts

System: CT

broker

System: CT

```json
{
  "sql": "",
  "explanation": "The request refers to 'the first result' (a prior query/CTE of checked IDs) which was not provided, and the referenced tables (ct.client_360, pipedrive.*, broker account verification/outdated flags) have no column details in the available schema.",
  "confide

Show the same checked IDs for the CT accounts of any role with a previously verified broker account now marked outdated from the first result, this time in descending user_id order. Keep every member and show only user_id.


System: CT

CT accounts

System: CT

broker

System: CT

```json
{
  "sql": "",
  "explanation": "The request depends on a prior result set and tables (ct.client_360, broker-account verification columns) that are not present in the provided schema, so no safe SELECT can be generated.",
  "confidence": "uncertain",
  "warnings": [
    "Schema lists tables

Show the same checked IDs for the CT accounts of any role with a notified broker account but no broker account that has ever been verified from the first result, this time in descending user_id order. Keep every member and show only user_id.


System: CT

CT accounts

System: CT

broker

System: CT

client

```json
{
  "sql": "",
  "explanation": "Cannot generate: the question references 'the third result' (a prior query not provided), requires ct.client_360 which is absent from the provided schema, and no column information is available for accounts, broker_accounts, or clients.",
  "confidence": "unc

Keep the CT accounts of any role with a notified broker account but no broker account that has ever been verified membership from the third result and count those distinct IDs as client_count. An empty result counts as zero.


System: CT

CT accounts

System: CT

broker

System: CT

client

```json
{
  "sql": "",
  "explanation": "The request depends on a prior 'third result' that was not provided, references columns (broker-account membership flags, ct.client_360 fields) not present in the schema (all tables list no columns), so no safe SELECT can be generated.",
  "confidence": "unce

Keep the CT accounts of any role with a previously verified broker account now marked outdated membership from the third result and count those distinct IDs as client_count. An empty result counts as zero.


System: CT

client

System: CT

System: PD

person ID

```json
{
  "sql": "",
  "explanation": "The schema context lists no columns for any table (including ct.client_360 and pipedrive objects), so I cannot verify column names for sell/buy currency declarations or user_id on the gold source.",
  "confidence": "uncertain",
  "warnings": ["No column defin

List every distinct private CT client records who declared at least one currency on both the sell and buy sides. Return only user_id, in ascending order; use the person ID for a Pipedrive-only person.


System: CT

client

```json
{
  "sql": "",
  "explanation": "The request cannot be satisfied: the provided schema lists no columns for any table, and ct.client_360 is not present, so the 'declared currency on sell and buy sides' condition and the gold projection fields cannot be mapped to real columns.",
  "confidence"

For exactly the private CT client records who declared at least one currency on both the sell and buy sides in the first checked result, return their distinct count as client_count. Keep that membership and return zero if it is empty.


System: CT

CT accounts

System: CT

brokers

System: CT

System: PD

person ID

SELECT ba.user_id AS user_id, NULL::integer AS pipedrive_person_id FROM public.broker_accounts ba WHERE ba.verified_at IS NOT NULL AND ba.broker_id IS NOT NULL GROUP BY ba.user_id HAVING COUNT(DISTINCT ba.broker_id) >= 2 ORDER BY 1

SELECT c.user_id FROM ct.client_360 c WHERE c.broker_verified = true GROUP BY c.user_id HAVING COUNT(DISTINCT c.broker_id) >= 2 ORDER BY c.user_id ASC

List every distinct CT accounts of any role that have at least two different verified brokers. Return only user_id, in ascending order; use the person ID for a Pipedrive-only person.


System: CT

client

System: CT

```json
{
  "sql": "",
  "explanation": "The request references prior-result IDs, a buy/sell currency-declaration predicate, and tables (ct.client_360, pipedrive.*) that are not present in the provided schema (all listed tables have no columns), so no valid query can be generated.",
  "confidence":

Show the same checked IDs for the private CT client records who declared at least one currency on both the sell and buy sides from the first result, this time in descending user_id order. Keep every member and show only user_id.


System: CT

CT accounts

System: CT

brokers

System: CT

client

```json
{
  "sql": "",
  "explanation": "The request references ct.client_360 and a prior 'first checked result' with verified broker columns, but none of these tables/columns exist in the provided schema (all tables list no columns), so no valid SELECT can be generated.",
  "confidence": "uncertain

For exactly the CT accounts of any role that have at least two different verified brokers in the first checked result, return their distinct count as client_count. Keep that membership and return zero if it is empty.


System: CT

client

```json
{
  "sql": "",
  "explanation": "The request references ct.client_360, pipedrive.* tables, and a prior 'third result' that do not exist in the provided schema (all tables list no columns), so no SQL can be generated.",
  "confidence": "uncertain",
  "warnings": ["Referenced tables (ct.client

Keep the private CT client records who declared at least one currency on both the sell and buy sides membership from the third result and count those distinct IDs as client_count. An empty result counts as zero.


System: CT

CT accounts

System: CT

brokers

System: CT

```json
{
  "sql": "",
  "explanation": "This request depends on a prior result ('the first result') and columns (e.g. ct.client_360 verified-broker flags) that are not present in the provided schema, so I cannot construct a valid query.",
  "confidence": "uncertain",
  "warnings": ["No prior-result

Show the same checked IDs for the CT accounts of any role that have at least two different verified brokers from the first result, this time in descending user_id order. Keep every member and show only user_id.


System: CT

CT accounts

System: CT

brokers

System: CT

client

```json
{
  "sql": "",
  "explanation": "The request depends on an unavailable prior result ('the third result') and requires tables (ct.client_360, pipedrive.*) not present in the provided schema, which lists no columns for any table.",
  "confidence": "uncertain",
  "warnings": ["No prior multi-re

Keep the CT accounts of any role that have at least two different verified brokers membership from the third result and count those distinct IDs as client_count. An empty result counts as zero.


4 fully registered corporate CT clients (cfx (corporate)) have no non-deleted, non-closed bookings

List every distinct corporate CT client records wi...

System: CT

client

System: CT

System: PD

person ID

SELECT a.id AS user_id FROM public.accounts AS a JOIN public.clients AS c ON c.user_id = a.id WHERE a.role = 'User' AND NOT a.skip_commission_calculations IS TRUE AND NOT c.type IS NULL AND c.type <> 'PersonalAccount' AND NOT c.completed_registration_at IS NULL AND NOT EXISTS(SELECT 1 FROM public.trade_bookings AS tb WHERE tb.user_id = a.id AND tb.status <> 'closed' AND tb.deleted_at IS NULL) ORDER BY 1 ASC LIMIT 10000

SELECT
  a.id AS user_id
FROM public.accounts AS a
JOIN public.clients AS c
  ON c.user_id = a.id
WHERE
  a.role = 'User'
  AND NOT a.skip_commission_calculations IS TRUE
  AND NOT c.type IS NULL
  AND c.type <> 'PersonalAccount'
  AND NOT c.completed_registration_at IS NULL
  AND NOT EXISTS(
    SELECT
      1
    FROM public.trade_bookings AS tb
    WHERE
      tb.user_id = a.id AND tb.status <> 'closed' AND tb.deleted_at IS NULL
  )
ORDER BY
  1 ASC
LIMIT 10000

'Corporate' means type is not null and not PersonalAccount, per the SQL filter

Commission-calculation-skipped accounts (skip_commission_calculations = TRUE) are excluded

When did each of these 4 clients complete registration, and who is the responsible account manager?

Do any of these 4 have bookings that were deleted or closed, versus never having booked at all?

All 4 rows share the same client type, cfx (corporate), so this is a single segment rather than a mix

The count is the complete list — rows returned matches the sample, capped at 10,000 but well under it

These are registered but dormant clients worth reviewing for onboarding follow-up

activation-definition activation-definition-gold onboarding-duration churn-tier-definitions declared-currency-intent client-type-sti-classes trade-existence-gold-booked

List every distinct corporate CT client records with completed registration who have no non-deleted, non-closed booking. Return only user_id, in ascending order; use the person ID for a Pipedrive-only person.

Reads accounts joined to clients by matching clients.user_id to accounts.id.

Keeps only rows where the account role is 'User', skip_commission_calculations is not true, client type is not null and not 'PersonalAccount', and completed_registration_at is not null.

Excludes any account that has a trade_bookings row with the same user_id where status is not 'closed' and deleted_at is null — i.e., accounts must have no open, non-deleted booking.

Returns the account id as user_id, sorted ascending, limited to 10,000 rows.

Summary: Finds account IDs that are 'User' role clients with a non-null, non-personal type and a completed registration, and that have no trade booking that is both not closed and not deleted.


4 corporate CT clients with completed registration have no non-deleted, non-closed bookings

For exactly the corporate CT client records with c...

System: CT

client

SELECT COALESCE(COUNT(DISTINCT a.id), 0) AS client_count FROM public.accounts a JOIN public.clients c ON c.user_id = a.id WHERE a.role = 'User' AND NOT a.skip_commission_calculations IS TRUE AND c.type IS NOT NULL AND c.type <> 'PersonalAccount' AND c.completed_registration_at IS NOT NULL AND NOT EXISTS (SELECT 1 FROM public.trade_bookings tb WHERE tb.user_id = a.id AND tb.status <> 'closed' AND tb.deleted_at IS NULL)

SELECT
  COALESCE(COUNT(DISTINCT a.id), 0) AS client_count
FROM public.accounts AS a
JOIN public.clients AS c
  ON c.user_id = a.id
WHERE
  a.role = 'User'
  AND NOT a.skip_commission_calculations IS TRUE
  AND NOT c.type IS NULL
  AND c.type <> 'PersonalAccount'
  AND NOT c.completed_registration_at IS NULL
  AND NOT EXISTS(
    SELECT
      1
    FROM public.trade_bookings AS tb
    WHERE
      tb.user_id = a.id AND tb.status <> 'closed' AND tb.deleted_at IS NULL
  )

Corporate defined as client type being non-null and not 'PersonalAccount'

Excludes accounts with skip_commission_calculations set to true and roles other than 'User'

Reading this as the registration-form funnel — started the signup wizard vs finished it (clients.completed_registration_at). If you meant activation (verified & ready to trade), say so.

List the 4 clients with their names, account IDs and registration dates

How many of these 4 have never had any booking at all, including closed or deleted ones?

The zero-booking check excludes only closed and deleted bookings, so clients whose bookings are all closed still count towards the 4.

Count is of distinct accounts, so each client is counted once.

For exactly the corporate CT client records with completed registration who have no non-deleted, non-closed booking in the first checked result, return their distinct count as client_count. Keep that membership and return zero if it is empty.

Joins accounts to clients on clients.user_id = accounts.id, so only accounts with a matching client row count.

Keeps only accounts where role = 'User' and skip_commission_calculations is not true.

Requires the client's type to be filled in and not equal to 'PersonalAccount'.

Requires completed_registration_at to be filled in.

Excludes any account that has at least one trade booking with status other than 'closed' and no deleted_at timestamp.

Counts the distinct account IDs; if the result is empty, COALESCE returns 0 as client_count.

Summary: Counts distinct account IDs for corporate, fully registered clients with no active (non-closed, non-deleted) trade bookings, returning zero if none match.


6 results — first client: Fictional Company 8

List every distinct CT client records whose client...

System: CT

client

System: CT

client type

System: CT

broker

System: CT

System: PD

person ID

SELECT COALESCE(c.user_id, pe.id) AS user_id FROM ct.client_360 AS c LEFT JOIN pipedrive.persons_enriched AS pe ON pe.id = c.user_id WHERE (c.client_type IS NULL OR c.client_type = '') AND EXISTS(SELECT 1 FROM ct.accounts AS a WHERE a.user_id = c.user_id) GROUP BY 1 ORDER BY 1 LIMIT 10000

SELECT a.id AS user_id FROM public.accounts AS a JOIN public.clients AS c ON c.user_id = a.id WHERE a.role = 'User' AND NOT a.skip_commission_calculations IS TRUE AND (c.type IS NULL OR TRIM(c.type) = '') AND EXISTS(SELECT 1 FROM public.broker_accounts AS ba WHERE ba.user_id = a.id) ORDER BY 1 ASC LIMIT 10000

List every distinct CT client records whose client type is unknown and who have at least one broker account. Return only user_id, in ascending order; use the person ID for a Pipedrive-only person.

Summary: Two queries each find distinct client identifiers of a given client type who hold at least one broker account, one from Gold/Pipedrive via client_360 joined to persons and accounts, the other from CT Ledger via clients and accounts joined to broker_accounts; both return user_id ascending, and the merged answer matches…


System: CT

client

System: CT

client type

System: CT

broker

```json
{
  "sql": "",
  "explanation": "The request depends on an undefined prior result ('the first checked result'), a client_type/broker-account relationship on ct.client_360, and none of the provided tables expose any column metadata, so no safe SELECT can be built.",
  "confidence": "uncertain

For exactly the CT client records whose client type is unknown and who have at least one broker account in the first checked result, return their distinct count as client_count. Keep that membership and return zero if it is empty.