KSQL for distinct values

Viewed 1218

How do I check if there are more than two records in a stream that are from the same userId but with a different productId. Lets say we have stream (uid,pid,price) I want to emit if from the same uid there are multiple different pid. What is the correct query syntax if pid is a string?

1 Answers

use count_distinct operator

 SELECT COUNT_DISTINCT(PID), uid
 FROM product_stream WINDOW TUMBLING (SIZE 5 SECONDS) GROUP BY uid
 HAVING COUNT_DISTINCT(PID) > 1 EMIT CHANGES;
Related