30 October 2018 · Ryan-Dallas ·       Add to Favorites   Report

How to count the frequency of multiple items in a row and across many rows in a Snowflake table

While performing data analysis, this is a classic scenario where we want to count the number of occurrences of a particular value. 

How to count the number of occurrences of a particular value in a table

EmployeeBadge_colorBadge_valid_days
JohnYellow2
JohnBlue2
JohnBlue2
JohnYellow2



To find the number of occurrences of Badge_color for each employee:

select
Employee,
Badge_color,
count(1) as num_times
from
MY_TABLE
group by Employee, Badge_color;

Ryan-Dallas

posted on 30 October 2018

Read great educational content like this and a lot more !

Members get free exclusive access to content, new courses, and discounts. Signup for a free account to write a post / comment / upvote posts. Creating an account takes less than 5 seconds and you can start earning badges & points too

Copied