Skip to content
Advertisement

Grouping sql result by a specific criteria

i am writing a query that supposed to show for a set of users, what emails he/she received, and if the email was open or not.

This is the result of the query:

THe problem i have, is that a user can receive the same email more than once per month, and open just one of them. One example is the JoinUs EmailTitle, that was received in the days 23 and 25 but just the 23 mail was open.

So in this case, when i have two equal emails send, i need to show just one line, and i need to show just the one that was open, preferably.

Advertisement

Answer

You can use rownumber and make a partition by userid and EmailTitle. That way in case of two emails you will get only the open one.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement