# Modalità di interrogazione dei dati

L’interrogazione dei dati avviene principalmente tramite l’utilizzo di **query SQL native** all’interno di Metabase, eseguite direttamente sul database ClickHouse.

Le query sono strutturate utilizzando costrutti standard SQL, tra cui:

* definizione di sottoquery tramite `WITH` (**Common Table Expressions**);
* operazioni di `JOIN` tra tabelle;
* aggregazioni tramite `GROUP BY`.

In diversi casi, le query includono logiche per la gestione di analisi temporali (es. aggregazioni per mese o anno) e segmentazioni dei dati in base a specifiche dimensioni (es. ente, servizio).

{% code title="Query SQL per il calcolo del numero totale di pratiche in carico, con applicazione dei filtri dinamici" %}

```sql
SELECT COUNT(a.status_name) AS "In carico"
FROM applications AS a
LEFT JOIN services AS s ON a.service_id = s.id
JOIN tenants AS t ON a.tenant_id = t.id
WHERE a.status_name = 'status_pending' AND {{Ente}}
```

{% endcode %}


---

# Agent Instructions: 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.opencityitalia.it/dashboard-di-monitoraggio-dei-servizi/analisi-dei-dati-metabase/modalita-di-interrogazione-dei-dati.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.
