I'm getting the error:
Cannot create the clustered index 'SalesByTerritory' on view 'Sample.wwi.SalesByTerritory' because it does not aggregate results. Consider changing the view definition.
I'm trying to create a Materialized View in Azure SQL Data Warehouse (now Azure Synapse). I'm just tring to create a view with the sales table and getting the territory name and date from another table. Below is the code I'm using:
CREATE MATERIALIZED VIEW wwi.SalesByTerritory
WITH (distribution = hash([Sale Key]))
AS
SELECT Sale.[Sale Key],
Sale.[Description],
Sale.[Quantity],
Sale.[Profit],
City.[Sales Territory],
SaleDate.[Date],
SaleDate.[Fiscal Month Label]
FROM wwi.fact_Sale Sale
JOIN wwi.dimension_City City ON Sale.[City Key] = City.[City Key]
JOIN wwi.dimension_Date SaleDate ON Sale.[Invoice Date Key] = SaleDate.[Date]
That is probably because the Azure Synapse (DW) Materialized views can only work when there is some aggregation (probably to ensure uniqueness of some columns). This page talks about needing either of the below 2 conditions to be true: