> For the complete documentation index, see [llms.txt](https://docs.docbits.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.docbits.com/advanced-functions-and-tools/sql-access.md).

# SQL Access

<figure><img src="https://578966019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FT2n2w4uDCJvv7CJ5zrdk%2Fuploads%2Fgit-blob-0282304b14050c894879e8e693bea68ab24ad617%2Fsql_direct_access_settings.png?alt=media" alt="SQL Direct Access Settings"><figcaption></figcaption></figure>

## Overview

In the DocBits settings module, administrators can directly access the BI database using SQL. This feature is designed for advanced data management and custom reporting needs.

### Accessing SQL Direct Access

Navigate to the SQL Direct Access section in the settings module. Here, you will find credentials and access details, including username, password, database name, and host information.

* **Username:** user\_23f3d6
* **Password:** *Encrypted*
* **Database:** demo
* **Host:** see in the Screenshot

## **Example Access Details:**

```sql
SELECT
    COUNT(*),
    status,
    invoice_type
FROM dashboard
GROUP BY
    status,
    invoice_type

```

#### Results of a Sample Query

The following results display the number of documents by their respective status and invoice type:

* **Ready for Validation:** 71 Invoices, 6 unspecified
* **Pending Confirmation:** 1 unspecified
* **Finished:** 3 unspecified, 1 Invoice
* **Error:** 2 unspecified

#### Using clickhouse-client for Terminal Access

For developers preferring terminal usage, access can be established via `clickhouse-client`:

```bash
clickhouse-client --host <hostname_or_ip> --port <port> --user <username> --password <your_password> --database <database_name>

```

### Creating Materialized Views

We recommend creating materialized views for pre-calculating data to enhance performance in analytics tools like PowerBI:

```sql
SELECT toStartOfWeek(created_on) as week_start, sum(toFloat64OrZero(field_value)) as total_sum
FROM document_extracted_data
WHERE field_name = 'total_amount'
GROUP BY week_start

```

This example shows how to group total amounts by the week they were created, which is useful for weekly financial summaries or audit trails.

## Additional Resources

For further assistance or advanced configurations, please consult our support team or access our comprehensive video training available in the help section.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.docbits.com/advanced-functions-and-tools/sql-access.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
