Grouping with a Case Statement

Using GROUP BY allows you to group columns to run specific SQL queries like aggregating data into a SUM, AVG or COUNT. With that, know which of the columns you want to GROUP BY and how you want to group them is important.

First, you’ll need to know that to set up the CASE STATEMENT we’re going to write as a column in a our select statement. In our case, in a group of emails that are accessing our site, we want to know how many clicks each email provider is accounting for since the beginning of August. We also would like to compare an individual email service provider against the rest. For this example, we’re going to use Gmail as our service provider.


Continue reading our Data Tutorial as we walk you through how to use a CASE STATEMENT to GROUP a column with an alias or new string.