| [ Web Proxy ] |
| Viewing: https://docs.stripe.com/data/write-queries | [Back] [Original] |
Anyone on your account with permission to view reports can use the Sigma query editor to compose new or modify existing queries. Our large language model (LLM)-based query assistant can even help you generate the SQL you need from a natural language prompt.
The navigator window to the left of the editor provides a set of tools to help you build your query. You can see:
Reports > Saved shows the lists of queries previously saved by you and your team. Templates provides a set of example queries representing the most common metrics and reports. Selecting a saved query or template loads it into the query editor, where you can click Run to regenerate and view the results.
To use a saved query as a starting point for your own custom report, either click its overflow menu () and choose Make a copy or load it into the editor and click Make a copy. This lets you modify the content in the editor and save your changes as a new query.
When you open the query editor, you can:
The following query uses the balance_transactions table to get information about the five most recent balance transactions related to refunds:
select date_format(created, '%Y-%m-%d') as day, id, amount, currency, source_id from balance_transactions where type = 'refund' order by day desc limit 5
Click Run to execute the query and view the results in a table below the editor. More complex queries might take a few moments longer to complete and display results. Attempting to run an invalid query generates an error message that contains the line number and position of the error.
The results of our sample query returns five rows, where each row corresponds to a particular balance transaction item, along with the requested information about them.
| day | id | amount | currency | source_id |
|---|---|---|---|---|
| 8/19/2026 | txn_yvuNl2nGlwoMqLY | -1,000 | usd | re_hg7Gd8wFFegaC6A |
| 8/19/2026 | txn_yjzFgCZNaAMSW2b | -1,000 | usd | re_fakOu5J3wWvDCzN |
| 8/19/2026 | txn_MjZMzGxKC94mDnO | -1,000 | usd | re_lwXaKcijIvdNA7H |
| 8/19/2026 | txn_ESLjut93qyxfOsW | -1,000 | eur | re_JLjKyDeL4EKsdRR |
| 8/19/2026 | txn_BUxDehe8ovuwaWr | -1,000 | usd | re_rEhz9qGB4jp1Qek |
You can join columns of type Primary key or Foreign key to similar columns in other tables:
For instance, you can join the charge_id column of the disputes table (a foreign key) to the id column of the charges table (a primary key).
Joining tables allows you to return richer results in your datasets. For example, you can modify our balance transaction example to join with the refunds table to provide further information.
select date_format(date_trunc('day', balance_transactions.created), '%Y-%m-%d') as day, balance_transactions.amount, balance_transactions.currency, balance_transactions.source_id, refunds.charge_id from balance_transactions inner join refunds -- Joining these tables to retrieve additional information on balance_transactions.source_id=refunds.id where balance_transactions.type = 'refund' order by day desc limit 5
This extended query now returns the original charge ID that the refund relates to.
| day | amount | currency | source_id | charge.id |
|---|---|---|---|---|
| 8/19/2026 | -1,000 | usd | re_QqZYAMPUthFNGCp | ch_Bx5XAcundNuyPX9 |
| 8/19/2026 | -1,000 | usd | re_ouXIvENCqtJt1Qo | ch_SyvQNMvtP6Yrm4P |
| 8/19/2026 | -1,000 | usd | re_ldMNIExKTcSFbpw | ch_2D38k3oNp40GMzN |
| 8/19/2026 | -1,000 | eur | re_KPrMy5EqM1gLAr3 | ch_euj0vh751pXGgIo |
| 8/19/2026 | -1,000 | usd | re_U5tYuGNiLsVNHPp | ch_vU4b2fgq3DR00kX |
Stripes query editor has a built-in LLM assistant that outputs standard ANSI SQL from a natural language prompt. The editor can perform the following modes:
For the most accurate suggestion, make sure you select the right mode for your prompt. When the editor contains content, the mode automatically switches to Edit. If you then decide to prompt for a new query without changing the mode, the resulting suggestion might be unexpectedly constrained based on whats already in the editor.
Open the Sigma query editor in the Dashboard.
Select the Generate mode and enter a question in the prompt field. The assistant:
Continue to prompt the assistant and view the resulting data until you get the information you want.
The following screenshot demonstrates how a prompt generated the same SQL as the example query shown at the beginning of this document:
Additional questions to modify the suggestions might include:
When asking for data about connected accounts, explicitly mention connected accounts in your query. For example: How many new subscriptions did I have from connected accounts last month?
Sigma saves every interaction you have with the assistant in the chat history for that query. Click the button in the top-right of the editor to open the chat history slider.
Within the chat history, you can see each prompt given to the assistant for the life of the query (not just the current session) and the assistants response. Click View SQL to see the SQL suggestion associated with any prompt. When open, click View in editor to reload that suggestion into the main editor window.
Help us continue to improve the assistant by responding to the Was this response helpful? prompt between the editor and the results table:
Click Yes or No.
Enter specific details about how the assistant performed for you and what we can do to improve. We welcome all opinions, whether its about the accuracy of the suggestion, the UI, or any other aspect of your experience with the assistant.
By using Sigma Assistant you agree that Stripe may log and use your chat entries to train and improve the Sigma Assistant capabilities. If you dont want to have your chat entries used for this purpose, you can opt-out in your settings.
You can schedule your queries on a daily, weekly, or monthly basis. We send results in an email or a webhook event.
Query results display in a table below the editor. You can:
You can also create a chart visualization for queries with fewer than 10,000 results. You can:
When you save a chart to a query, the chart appears with your chosen settings every time you run the query. Charts are only editable by the author of the query.
Amounts are expressed in the lowest available currency unit, such as cents for USD or yen for JPY. For example, an amount of 1,000 with a currency of usd equates to 10 USD.
Click Download CSV to export your results for use in spreadsheet applications or other reporting tools. The downloaded CSV includes all query results, so youre not limited to the 1,000 viewable results.
You can save queries and execute them programmatically in your own environment with the Query Run API.
After you run a query, click Save. Stripe automatically generates an editable title for your query.
The queries you save are added to Reports > Saved and made available to every team member on your account. Each saved query is given a unique URL you can share by clicking Share. You can use this link as a shortcut to a particular report you regularly use, or share it directly with other team members on the Stripe account.
You can only share queries with team members. Shared queries are read-only, so other team members cant modify the queries you create. If a team member wants to make changes to your query, they can make a copy and edit it accordingly.
| Web Proxy Viewer | New URL | Original Page |