By default, query results are flat and unsorted. To ease analysis, you can lay out results as a cross-tabulation or sort results by multiple fields.
-->Per impostazione predefinita, i risultati delle query sono piatti e non ordinati. Per facilitare il confronto e l'analisi dei dati, puoi:
- Ordina i risultati in ordine crescente o decrescente, in base a uno o più campi.
- Usa una tabulazione incrociata o un layout incrociato per raggruppare i risultati in orizzontale e in verticale in base alle dimensioni che hai scelto e applica valori di aggregazione come COUNT o MAX alle righe o alle colonne.
From the Layout menu, select whether to lay out the results as flat or crosstab:
- Flat —By default, query results appear flat, with all fields as separate columns, like a table.
- Crosstab —To help compare and analyze data, use a cross-tabulation—or crosstab—layout. Crosstab groups the results horizontally and vertically based on dimensions you choose. To further help summarize the data, you can also apply calculations—such as COUNT or MAX—to values.
Ad esempio, i risultati di una query forniscono i dati sulle vendite in un layout piatto e tabellare per impostazione predefinita:
| Regione | Importo delle vendite | Anno fiscale |
|---|---|---|
| Nord | 100 | 2020 |
| Nord | 50 | 2020 |
| Sud | 100 | 2019 |
| Sud | 250 | 2020 |
| Est | 200 | 2019 |
| Est | 50 | 2019 |
| Ovest | 100 | 2019 |
| Ovest | 100 | 2020 |
Con i risultati delle tabelle incrociate, puoi disporre e riassumere i dati per confrontare le vendite totali di ogni regione durante ogni anno fiscale:
| Regione | 2019 | 2020 |
|---|---|---|
| Est | 250 | 0 |
| Nord | 0 | 150 |
| Sud | 100 | 250 |
| Ovest | 100 | 100 |
Disporre i risultati della tabulazione incrociata
Per facilitare l'analisi dei dati categorici, puoi disporre i risultati come tabulazione incrociata, con righe, colonne e valori in Builder o SQL .
- Nella query, aggiungi i campi da includere nei risultati:
- In Builder, aggiungi i campi sorgente e i calcoli alla scheda Fields.
- In SQL, componi l'SQL della query e verifica che non ci siano errori di sintassi.
Per ogni campo contenuto nell'istruzione SELECT, usa un'istruzioneASper specificare la sua intestazione nel layout della tabella incrociata, anche se è uguale al nome del campo. Ad esempio,SELECT field_name1 AS "alias", field_name2 AS "field_name2" FROM source_name.
- Dal pannello Crosstab , seleziona Enable Crosstab, e specifica come visualizzare i campi nei risultati:
- Per visualizzare i valori di in verticale, come Regione nel nostro esempio, lascia il suo campo da Righe e seleziona se ordinare i dati in ordine crescente o decrescente.
- Per visualizzare i valori in orizzontale, come Anno fiscale nel nostro esempio, sposta il suo campo da Righe a Colonne, e seleziona se ordinare i dati in ordine crescente o decrescente.
- Per applicare un calcolo a un valore all'interno del confronto, sposta il suo campo da Righe a Valori, e seleziona l'aggregazione da utilizzare come DISTINCTCOUNT o SUM. Per visualizzare il valore come totale generale, in Totali, seleziona se deve apparire per righe o colonne.
Nota: Per rimuovere una riga dai risultati, cancella il suo campo dalla query.
- Per visualizzare l'anteprima dei risultati nel layout a tabelle incrociate, clicca su Esegui query .
- Clicca su Salva .
- In the query, add the source fields and calculations to include in the results.
-
From the toolbar, select Layout
, Crosstab.
-
On the Fields tab, specify how to display the
fields in the results:
- For values to display vertically, such as Region in our example, leave its field under Rows.
- For values to display horizontally, such as Fiscal Year in our example, move its field from Rows to Columns.
- To apply a calculation to a value within the comparison, move its field from Rows to Values, and select the formula to use such as DISTINCTCOUNT or SUM.
Note: To remove a row from the results, delete its field from the query.
- To view the results in the crosstab layout, click Run Query .
- Click Save .
- In the query, add the source fields and calculations to include in the results.
-
From the Layout
panel, select Enable Crosstab, and specify how
to display the fields in the results:
- For values to display vertically, such as Region in our example, leave its field under Rows, and select whether to sort its data in ascending or descending order.
- For values to display horizontally, such as Fiscal Year in our example, move its field from Rows to Columns.
- To apply a calculation to a value within the comparison, move its field from Rows to Values, and select the aggregation to use such as DISTINCTCOUNT or SUM. To display the value as a grand total, in Totals, select whether it should appear for rows or columns.
Note: To remove a row from the results, delete its field from the query.
- To preview the results in the crosstab layout, click Run Query .
- Click Save .
- In the editor, compose the query's SQL, and verify no syntax errors occur.
-
For each field in
the
SELECTstatement, use anASstatement to specify its header in the crosstab layout, including if the same as the field's name. For example,SELECT field_name1 AS "alias", field_name2 AS "field_name2" FROM source_name. -
From the Layout
panel, select Enable Crosstab, and specify how
to display the fields in the results:
- For values to display vertically, such as Region in our example, leave its field under Rows.
- For values to display horizontally, such as Fiscal Year in our example, move its field from Rows to Columns.
- To apply a calculation to a value within the comparison, move its field from Rows to Values, and select the formula to use such as DISTINCTCOUNT or SUM. To display the value as a grand total, in Totals, select whether it should appear for rows or columns.
Note: To remove a row from the results, delete its field from the query.
- To preview the results in the crosstab layout, click Run Query .
- Click Save .
Include grand totals in crosstab results
To help summarize values in crosstab results, you can include grand totals for columns or rows in either Builder or SQL:
- When you set up the crosstab layout, drag the field with the values to calculate from Rows to Values, and select the aggregation to use, such as DISTINCTCOUNT or SUM.
-
From the toolbar, click Totals, and select whether to show
the grand totals for rows or columns.
<!-- - Click Save .
Disporre i risultati in modo piatto
<!--By default, query results appear in a flat layout. To return to a flat layout after setting up crosstab results, select Layout , Flat from the toolbar.
Per impostazione predefinita, i risultati delle query appaiono in un layout piatto. Per riportare i risultati della crosstab a un layout piatto, deseleziona Abilita crosstab dal pannello Layout .
Ordinamento dei risultati piatti
Per impostazione predefinita, i risultati delle query non appaiono in ordine. In Builder o SQL, puoi ordinare i risultati in ordine crescente o decrescente in base a uno o più campi.
- Nella scheda Ordina, sposta ogni campo da ordinare da Non ordinato a Ordinato, e seleziona se ordinare i dati in ordine crescente o decrescente .
- Se fai un ordinamento in base a più campi, alla voce Ordinati, disponili nell'ordine in cui vuoi ordinare i loro dati. Ad esempio, potresti voler ordinare prima in ordine crescente un campo e poi in ordine decrescente un altro.
- Clicca su Salva .
Quando componi l'istruzione SQL della query, usa una parola chiave ORDER BY per specificare il campo da ordinare in ordine crescente (ASC) o decrescente (DESC), ad esempio ORDER BY field_header ASC.
Per ordinare in base a più campi, separali con una virgola, ad esempio ORDER BY field_header1 ASC, field_header2 DESC.