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.
-->Domyślnie wyniki zapytań są płaskie i nieposortowane. Możesz porównywać i analizować dane:
- Sortuj wyniki w porządku rosnącym lub malejącym na podstawie jednego lub kilku pól.
- Użyj układu tabel krzyżowych lub krzyżowych, aby pogrupować wyniki w poziomie i w pionie na podstawie wybranych wymiarów i zastosować wartości agregacji - takie jak COUNT lub MAX - do wierszy lub kolumn.
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.
Przykładowo, wyniki zapytania domyślnie dostarczają danych sprzedażowych w płaskim, tabelarycznym układzie:
| Region | Kwota sprzedaży | Rok podatkowy |
|---|---|---|
| Północ | 100 | 2020 |
| Północ | 50 | 2020 |
| Południe | 100 | 2019 |
| Południe | 250 | 2020 |
| Wschód | 200 | 2019 |
| Wschód | 50 | 2019 |
| Zachód | 100 | 2019 |
| Zachód | 100 | 2020 |
Dzięki wynikom tabeli krzyżowej możesz rozłożyć i podsumować dane, aby porównać całkowitą sprzedaż każdego regionu w każdym roku podatkowym:
| Region | 2019 | 2020 |
|---|---|---|
| Wschód | 250 | 0 |
| Północ | 0 | 150 |
| Południe | 100 | 250 |
| Zachód | 100 | 100 |
Rozmieść wyniki analizy krzyżowej
Aby ułatwić analizę danych kategorialnych, możesz przedstawić wyniki w formie tabeli krzyżowej, z wierszami, kolumnami i wartościami w Builder lub SQL .
- W zapytaniu dodaj pola, które mają zostać uwzględnione w wynikach:
- W Builder, dodaj pola źródłowe i obliczenia do zakładki Fields.
- W witrynie SQL utwórz kod SQL zapytania i sprawdź, czy nie występują błędy składni. Dla każdego pola w instrukcji
SELECT, użyj instrukcjiAS, aby określić jego nagłówek w układzie tabeli krzyżowej, nawet jeśli jest taki sam jak nazwa pola. Na przykład,SELECT field_name1 AS "alias", field_name2 AS "field_name2" FROM source_name.
- W panelu Crosstab wybierz Enable Crosstab i określ sposób wyświetlania pól w wynikach:
- W przypadku wartości, które mają być wyświetlane pionowo, takich jak Region w naszym przykładzie, pozostaw jego pole w Wiersze i wybierz, czy chcesz sortować jego dane w porządku rosnącym czy malejącym.
- Aby wyświetlić wartości poziomo, takie jak Fiscal Year w naszym przykładzie, przenieś jego pole z Rows do Columns i wybierz, czy chcesz sortować dane w porządku rosnącym czy malejącym.
- Aby zastosować obliczenie do wartości w porównaniu, przenieś jej pole z Rows do Values i wybierz agregację do użycia, taką jak DISTINCTCOUNT lub SUM. Aby wyświetlić wartość jako sumę całkowitą, na stronie Totals wybierz, czy ma być ona wyświetlana dla wierszy czy kolumn.
Uwaga: Aby usunąć wiersz z wyników, usuń jego pole z zapytania.
- Aby wyświetlić podgląd wyników w układzie tabeli krzyżowej, kliknij Uruchom zapytanie .
- Kliknij Zapisz .
- 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 .
Rozłóż wyniki na płasko
<!--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.
Domyślnie wyniki zapytań wyświetlane są w układzie płaskim. Aby przywrócić płaski układ wyników tabel krzyżowych, usuń zaznaczenie opcji Enable crosstab w panelu Layout .
Sortuj płaskie wyniki
Domyślnie wyniki zapytań nie są sortowane. W Builder lub SQL możesz sortować wyniki w porządku rosnącym lub malejącym według jednego lub więcej pól.
- Na karcie Sortuj przenieś każde pole do sortowania według z Nieposortowane do Posortowane i wybierz, czy dane mają być sortowane rosnąco czy malejąco .
- Jeśli sortujesz według wielu pól, w sekcji Sortowane ułóż je w kolejności sortowania danych. Na przykład, możesz chcieć sortować najpierw w porządku rosnącym według jednego pola, a następnie w porządku malejącym według innego.
- Kliknij Zapisz .
Podczas tworzenia instrukcji SQL zapytania, użyj słowa kluczowego ORDER BY , aby określić pole do sortowania w porządku rosnącym (ASC) lub malejącym (DESC), np. ORDER BY field_header ASC.
Aby sortować według wielu pól, oddziel każde z nich przecinkiem, np. ORDER BY field_header1 ASC, field_header2 DESC.