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.
-->Standaard zijn queryresultaten plat en ongesorteerd. Om gegevens te helpen vergelijken en analyseren, kunt u:
- Sorteer de resultaten in oplopende of aflopende volgorde, op basis van één of meer velden.
- Gebruik een kruistabel- of kruistabellay-out om de resultaten horizontaal en verticaal te groeperen op basis van dimensies die u kiest en pas aggregatiewaarden, zoals COUNT (TELLEN) of MAX (MAX), toe op rijen of kolommen.
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.
De resultaten van een query bieden bijvoorbeeld standaard verkoopgegevens in een platte lay-out in tabelvorm:
| Regio | Verkoop Bedrag | Boekjaar |
|---|---|---|
| Noord | 100 | 2020 |
| Noord | 50 | 2020 |
| Zuid | 100 | 2019 |
| Zuid | 250 | 2020 |
| Oost | 200 | 2019 |
| Oost | 50 | 2019 |
| West | 100 | 2019 |
| West | 100 | 2020 |
Met kruistabellen kunt u de gegevens indelen en samenvatten om de totale verkoop van elke regio tijdens elk boekjaar te vergelijken:
| Regio | 2019 | 2020 |
|---|---|---|
| Oost | 250 | 0 |
| Noord | 0 | 150 |
| Zuid | 100 | 250 |
| West | 100 | 100 |
Resultaten van kruistabellen weergeven
Om de analyse van categorische gegevens te vergemakkelijken, kunt u de resultaten opmaken als een kruistabel, met rijen, kolommen en waarden in Builder of SQL .
- Voeg in de query de velden toe die u in de resultaten wilt opnemen:
- In Builder, voegt u de bronvelden en berekeningen toe aan het tabblad Velden.
- In SQL, stelt u de SQL van de query samen en controleert u of er geen syntaxfouten optreden. Gebruik voor elk veld in het
SELECTstatement eenASstatement om de koptekst ervan in de kruistabelopmaak te specificeren, zelfs als deze hetzelfde is als de naam van het veld. Bijvoorbeeld,SELECT field_name1 AS "alias", field_name2 AS "field_name2" FROM source_name.
- Selecteer in het paneel Kruistabel Kruistabel inschakelen en geef aan hoe de velden in de resultaten moeten worden weergegeven:
- Voor waarden die verticaal moeten weergeven, zoals Regio in ons voorbeeld, laat u het veld onder Rijen staan en selecteert u of de gegevens oplopend of aflopend moeten worden gesorteerd.
- Voor waarden die horizontaal weergeeft, zoals Fiscaal jaar in ons voorbeeld, verplaatst u het veld van Rijen naar Kolommen, en selecteert u of de gegevens oplopend of aflopend moeten worden gesorteerd.
- Om een berekening toe te passen op een waarde binnen de vergelijking, verplaatst u het veld van Rows naar Values, en selecteert u de aggregatie die u wilt gebruiken, zoals DISTINCTCOUNT of SUM. Om de waarde als eindtotaal weer te geven, selecteert u in Totalen of het voor rijen of kolommen moet verschijnen.
Opmerking: Om een rij uit de resultaten te verwijderen, verwijdert u het betreffende veld uit de query.
- Om de resultaten in de kruistabellay-out te bekijken, klikt u op Query uitvoeren .
- Klik op Opslaan .
- 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 .
Platte resultaten leggen
<!--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.
Standaard worden queryresultaten in een platte lay-out weergegeven. Om de resultaten van kruistabellen terug te brengen naar een vlakke lay-out, deselecteert u Kruistabel inschakelen in het paneel Lay-out .
Platte resultaten sorteren
Standaard worden queryresultaten ongesorteerd weergegeven. In Builder of SQL kunt u de resultaten oplopend of aflopend sorteren op één of meer velden.
- Op het tabblad Sorteren verplaatst u elk veld waarop u wilt sorteren van Ongesorteerd naar Gesorteerd en selecteert u of de gegevens oplopend of aflopend moeten worden gesorteerd.
- Als u op meerdere velden sorteert, zet u ze onder Gesorteerd in de volgorde waarin u de gegevens wilt sorteren. U wilt bijvoorbeeld eerst oplopend sorteren op een veld en daarna aflopend op een ander veld.
- Klik op Opslaan .
Wanneer u de SQL-instructie van de query samenstelt, gebruik dan een ORDER BY sleutelwoord om het veld te specificeren dat oplopend (ASC) of aflopend (DESC) gesorteerd moet worden, zoals ORDER BY field_header ASC.
Om op meerdere velden te sorteren, scheidt u elk veld met een komma, zoals ORDER BY field_header1 ASC, field_header2 DESC.