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.
-->デフォルトでは、クエリ結果はフラットで並び替えされていません。データの比較と分析には、次のような方法がある:
- 1つ以上のフィールドに基づいて、結果を昇順または降順で並べ替える。
- クロス集計レイアウトを使用して、選択したディメンションに基づいて結果を水平方向および垂直方向にグループ化し、COUNTやMAXなどの集計値を行または列に適用する。
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.
たとえば、クエリの結果は、デフォルトではフラットな表形式のレイアウトで売データを提供します。
地域 | 売上高 | 会計年度 |
---|---|---|
北 | 100 | 2020 |
北 | 50 | 2020 |
南 | 100 | 2019 |
南 | 250 | 2020 |
東 | 200 | 2019 |
東 | 50 | 2019 |
西 | 100 | 2019 |
西 | 100 | 2020 |
クロス集計結果を使えば、データを並べて要約し、各地域の各年度の総売上高を比較することができる:
地域 | 2019 | 2020 |
---|---|---|
東 | 250 | 0 |
北 | 0 | 150 |
南 | 100 | 250 |
西 | 100 | 100 |
クロス集計結果を並べる
カテゴリデータの分析を簡易化するため、[ビルダー]または[SQL]
- クエリで、結果に含めるフィールドを追加する:
- ビルダーで、ソースフィールドと計算を[フィールド]タブに追加します。
-
SQL で、クエリのSQLを作成し、構文エラーが発生しないことを確認する。
SELECT
ステートメント の各フィールドに対して、AS
ステートメントを使用し、フィールド名と同じであっても、クロス集計のレイアウトでそのヘッダーを指定する。例えば、SELECT field_name1 AS "alias", field_name2 AS "field_name2" FROM source_name
.
- [クロス集計]からパネルで、[クロス集計を有効にする]を選択し、結果にフィールドを表示する方法を指定します。
- この例の[地域]のように、値を垂直に表示するには、フィールドを[行]の下に残し、データを昇順または降順のどちらで並べ替えるかを選択します。
- この例の[会計年度]のように、値を水平に表示するには、フィールドを[行]から[列]に移動し、データを昇順で並べ替えるか降順で並べ替えるかを選択します。
- 比較内の値に計算を適用するには、そのフィールドを行 から値 に移動し、DISTINCTCOUNT や SUM などの使用する集計を選択します。値を総計として表示するには、合計 で、行と列のどちらに表示するかを選択する。
注: 結果から行を削除するには、クエリからそのフィールドを削除する。
- 結果をクロス集計レイアウトでプレビューするには、[クエリの実行]をクリックします。
- [保存]をクリックします。
- 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
SELECT
statement, use anAS
statement 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 .
フラットな結果をレイアウトする
<!--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.
デフォルトでは、クエリ結果はフラットレイアウトで表示されます。クロス集計の結果をフラットレイアウトに戻すには、レイアウトパネルから、クロス集計を有効にする の選択を解除する。
フラットな結果を並べ替える
デフォルトでは、クエリ結果は並び替えされていません。ビルダー またはSQL のいずれかで、1つまたは複数のフィールドに従って、結果を昇順または降順に並べ替えることができます。
- [並べ替え]タブで、並べ替える必要のある各フィールドを[未ソート]から[ソート済み]に移動し、データを昇順または降順のどちらで並べ替えるかを選択します。
- 複数のフィールドに従って並べ替える場合は、Sortedから 、データの並べ替え順に並べ替える。例えば、まずあるフィールドに従って昇順に並べ、次に別のフィールドに従って降順に並べたい場合がある。
- [保存]をクリックします。