> 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="/files/lt04SMYWgJqFHqKT9mO8" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
