count(distinct ) over() is supported?
Kaito
Employee
I get the following error when I use "count(distinct ) over()". If you have a workaroud, could you share it with me?
==Error message== [Vertica][VJDBC](7830) ERROR: Only MIN/MAX and AND/OR are allowed to use DISTINCT ===============****
Thanks in advance,____> > > > > ``>
0
Comments
Hi,
Maybe the CONDITIONAL_CHANGE_EVENT analytic function can help?
Example:
See:
https://www.vertica.com/docs/9.2.x/HTML/Content/Authoring/SQLReferenceManual/Functions/Analytic/CONDITIONAL_CHANGE_EVENTAnalytic.htm
Thank you, Jim. I am going to test this.
Window DISTINCT_COUNT can be implemented as a two step calculation. 1) you do window Dense_rank() 2) You take window MAX()
Try this example:
WITH DATA AS
(
SELECT 1 AS ID, 1 AS Val UNION ALL
SELECT 1 AS ID, 1 AS Val UNION ALL
SELECT 1 AS ID, 2 AS Val UNION ALL
SELECT 1 AS ID, 2 AS Val UNION ALL
SELECT 1 AS ID, 3 AS Val UNION ALL
SELECT 2 AS ID, 4 AS Val UNION ALL
SELECT 2 AS ID, 5 AS Val UNION ALL
SELECT 2 AS ID, 5 AS Val UNION ALL
SELECT 3 AS ID, 6 AS Val UNION ALL
SELECT 3 AS ID, 7 AS Val UNION ALL
SELECT 3 AS ID, 8 AS Val UNION ALL
SELECT 3 AS ID, 9 AS Val
)
SELECT ID, Val, MAX(DR) OVER (PARTITION BY ID) AS PARTITION_DISTINCT_COUNT FROM
(
SELECT ID, Val, DENSE_RANK() OVER (PARTITION BY ID ORDER BY VAL) AS DR FROM DATA
) a