# What is SQL in game analytics?

> SQL is the query language of most analytics databases. In game analytics it counts events, players or revenue in groups that ready-made reports lack.

By Yos Riady. Updated 2026-11-18. Published 2026-11-18. Canonical URL: https://manalens.dev/glossary/sql

SQL is the query language that most analytics databases use. In game analytics, a SQL query can count events, players or revenue in any grouping that a ready-made report does not offer, such as fail rate by level and build. Manalens runs read-only ClickHouse SQL on your raw events.

## Key points

- Manalens runs read-only ClickHouse SQL on raw_events, sessions and session_events.
- A query returns at most 200 rows and stops after 8 seconds.
- Exclude bot rows and count events with uniqExact(message_id), because a client retry can repeat a row.

## How does SQL work in Manalens?

The Explorer runs read-only SQL on the table raw_events, where each row is one event. The tables sessions and session_events hold sessions. Read fields in context and properties with JSONExtractString() or JSONExtractFloat().

Write one SELECT or WITH statement. A result has at most 200 rows, and a query stops after 8 seconds. You can run 10 queries a minute, and a project can run 30. raw_events includes bot rows, so exclude them with JSONExtractString(context, 'device') != 'bot'. Use uniqExact(message_id) for exact event counts, because a client retry can repeat a row.

Sources: Manalens SQL explorer guide.

## What does an example look like?

Example: the fail rate of each level is fails / starts. The query below counts both for each level. With example numbers of 480 starts and 168 fails on level 3, the fail rate is 168 / 480 = 35%.

``` SQL
SELECT JSONExtractInt(properties, 'level') AS level,
       uniqExactIf(message_id, event = 'level_start') AS starts,
       uniqExactIf(message_id, event = 'level_fail') AS fails,
       round(fails / starts * 100, 1) AS fail_rate
FROM raw_events
WHERE type = 'track'
  AND event IN ('level_start', 'level_fail')
  AND JSONExtractString(context, 'device') != 'bot'
GROUP BY level
ORDER BY level
```

Sources: worked example; Manalens SQL explorer guide and game events documentation.

## Why does SQL matter for indie PC and web games?

Games have their own questions, such as which weapon players pick or which level each build makes harder. A fixed report cannot know them in advance. SQL answers them on your own events, and you can save the query as a dashboard chart.

ClickHouse says uniqExact gives the exact number of different values and uses more memory than uniq. Exact counts matter when you compare small groups.

- [Difficulty tuning with data: fail rates and retries](https://manalens.dev/blog/game-difficulty-tuning-analytics)
- [SQL explorer](https://manalens.dev/features/sql-explorer)
- [Custom dashboards](https://manalens.dev/features/custom-dashboards)

Sources: ClickHouse documentation: uniqExact; Manalens SQL explorer guide.

## Frequently asked questions

### Can I change data with SQL in Manalens?

No. The Explorer runs read-only SQL. Write one SELECT or WITH statement on raw_events, sessions or session_events. A result has at most 200 rows, and a query stops after 8 seconds. You can run 10 queries a minute, and a project can run 30, so group and count in the query instead of listing rows.

### How do I keep a SQL query?

The Explorer does not save queries. Open a dashboard, click Add chart, then Blank chart, paste the query into the SQL query box, name the columns to draw and save the chart. An AI tool can run the same SQL with the MCP tool execute_query and the query:read scope.

### Why use uniqExact(message_id) instead of count()?

A client retry can repeat a row in raw_events, so count() can count one event twice. uniqExact(message_id) counts each event once. ClickHouse says uniqExact gives the exact number of different values and uses more memory than uniq. Exact counts matter when you compare small groups, such as one level or one build.

## Sources

- [ClickHouse documentation: uniqExact (read 19 November 2026)](https://clickhouse.com/docs/en/sql-reference/aggregate-functions/reference/uniqexact)

## Related guides

- [Difficulty tuning with data: fail rates and retries](https://manalens.dev/blog/game-difficulty-tuning-analytics)
- [SQL explorer](https://manalens.dev/features/sql-explorer)
- [Custom dashboards](https://manalens.dev/features/custom-dashboards)
- [Game analytics dashboard](https://manalens.dev/glossary/dashboard)
- [Data sampling](https://manalens.dev/glossary/sampling)
