> For the complete documentation index, see [llms.txt](https://docs.rumi.systems/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rumi.systems/rumi-cli/commands/tools/txnstats/query.md).

# query

The `query` subcommand executes a SQL-like query against transaction logs and joins the results with per-transaction statistics, outputting to CSV.

{% hint style="warning" %}
**Note**: This tool is experimental and still in incubation.
{% endhint %}

## Usage

```bash
rumi tools txnstats query [options]
```

## Options

| Option                       | Description                                                    |
| ---------------------------- | -------------------------------------------------------------- |
| `-l, --log <file>`           | **(Required)** Path to the main recovery transaction log       |
| `-q, --query <sql>`          | **(Required)** SQL-like query to execute                       |
| `-o, --output <file>`        | Output CSV file (default: `txnstats.csv`)                      |
| `-m, --include-message-logs` | Include inbound/outbound message logs in query (default: true) |

## Prerequisites

The query command expects these related log files in the same directory as the main log:

| File                  | Description                     |
| --------------------- | ------------------------------- |
| `<name>.log`          | Main recovery transaction log   |
| `<name>.txnstats.log` | Per-transaction statistics log  |
| `<name>.in.log`       | Inbound message log (optional)  |
| `<name>.out.log`      | Outbound message log (optional) |

## Example

```bash
rumi tools txnstats query \
  -l /path/to/myapp.log \
  -q "SELECT simpleClassName, timestamp FROM logs WHERE timestamp BETWEEN 'today at 3pm' AND 'today at 3:05pm'" \
  -o results.csv
```

The output CSV will contain:

* Fields selected in the query
* Transaction timing statistics joined by transaction ID
* Inbound and outbound message timing details (when applicable)

## Compatibility

{% hint style="info" %}
**3.x Compatibility**: For logs created with Rumi 3.x, use the `--3x` flag before the command:

```bash
rumi --3x tools txnstats query -l /path/to/myapp.log -q "SELECT * FROM logs"
```

{% endhint %}

## See Also

* [txnstats](/rumi-cli/commands/tools/txnstats.md) - Transaction stats tools overview
* [txnstats dump](/rumi-cli/commands/tools/txnstats/dump.md) - Dump transaction stats to CSV
* [Configuring Per-Transaction Statistics](/rumi-core/guides/developing-applications/configuring-the-runtime/monitoring/per-transaction-statistics.md) - How to enable per-transaction stats logging
* [Querying Transaction Logs](/rumi-core/guides/operating-applications/analysis-and-troubleshooting/querying-transaction-logs.md) - Understanding the query syntax
