How to add expression on result of aggregate function when create Materialized View in Synapse
zmsoft
470
Reputation points
Hi there,
When I creating materialized view in synapse, i got an error, it says "because the select list of the view contains an expression on result of aggregate function or grouping column. Consider removing expression on result of aggregate function or grouping column from select list."
But I need to use the case when expression to generate one of the columns, Any suggestion?
My code is:
CREATE MATERIALIZED VIEW [MaterializedView].[MaterializedView123]
WITH (
DISTRIBUTION = ROUND_ROBIN
-- ,FOR_APPEND
)
AS
with base as (
SELECT
[A],
[B],
[C],
[D],
CASE WHEN [A] LIKE '%cat%'
OR [A] LIKE '%dog%'
OR [A] LIKE '%pig%' THEN 'X'
ELSE ''
END AS AFlag
FROM [ABC].[ABC123]
)
SELECT
[A],
[B],
[C],
[D],
AFlag,
count_big(*) as cb
FROM base
GROUP BY
[A],
[B],
[C],
[D],
AFlag;
Thanks
Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,378 questions
Sign in to answer