How to Use GROUP BY
GROUP BY is completed in Coalesce by adding your GROUP BY clause after the FROM statement, as well as after any other precursor statements like JOINs and/or a WHERE clause, in the Join tab of your Node Editor of the Node where you will complete the GROUP BY.
![](https://files.readme.io/6198b9a-group_by_example.png)
You will have to ensure your columns are configured correctly in your Mapping tab in terms of aggregation Transforms on column you wish to aggregate and Sources for columns you wish to GROUP BY in order for the GROUP BY to execute successfully.
![](https://files.readme.io/ad691da-grou_by_mapping_config.png)
GROUP BY Detailed Example
To provide a more detailed example, let's say you have a raw table of monthly sales amounts by store and month that you'd like to transform and load into a Fact Table of sales amounts by store in total. But rather than loading the actual store value into your Fact Table, you want to pull in the corresponding dimension key for each store from your Store Dimension, so you also need to join to your Store Dimension while completing this transform and load.
![](https://files.readme.io/fb2708b-group_by_detailed_example.png)
-
Add a Fact Node from your main source (
MONTHLY_SALES
). -
Remove the columns you don't want to include in your new Fact (
STORE
in its raw form andMONTH
) and configure your aggregations on your columns.
![](https://files.readme.io/1353925-remove_columns_fact_node_group_by.png)
- Map in the key from your Store Dimension (
DIM_STORE
).
![](https://files.readme.io/4eff37f-dim_store_map_key_group_by.png)
- Configure your join between your main source (MONTHLY_SALES) and your Store Dimension (
DIM_STORE
).
![](https://files.readme.io/9987675-group_by_step_4.png)
- Add a GROUP BY clause after your join on your Store Dimension key (
DIM_STORE.DIM_STORE_KEY
).
![](https://files.readme.io/1de8b31-group_by_step_5.png)
- Within the Node Editor:
- Validate Select.
- Validate Create.
- Create.
- Validate Run.
- Fetch data, and view grouped results.
![](https://files.readme.io/874f37a-group_by_step_six.png)
Updated about 2 months ago