[SalesForce] Marketing Cloud COUNT and Group by specific value

I'm trying to create a SQL Query which counts the same values in a Data extensions and Groups them by a Unique Value.

Usecase: My data extension looks like this:

enter image description here

I want to see how many email addresses have used the same UniqueCode. Currently I have the following SQL running, but somehow he doesn't show me the count of a UniqueCode:

    SELECT COUNT(distinct email) as test1 , UniqueCode AS test2
  FROM DataExtension
  GROUP BY UniqueCode

The target Data Extension does contain the email and UniqueCode field, but I only receive the UniqueCodes or email.

Can someone help me?

Here is a screenshot on how I have it in mind:

enter image description here

Best Answer

Now as answer (that the question becomes solved and has an answer). You cannot use fields which are not part of the group by clause.

To be honest i think its just SELECT COUNT(*) as UniqueCodeCount, UniqueCode FROM DataExtension GROUP BY UniqueCode or SELECT COUNT(UniqueCode) as UniqueCodeCount, UniqueCode FROM DataExtension GROUP BY UniqueCode or however you want those column to be named (called it UniqueCodeCount)

Related Topic