Filtering data according to a reference category – The Venn-Diagrams logic

Filtering data according to a reference category – The Venn-Diagrams logic

Let’s say you have data of purchases by date (year and month) made by consumers, with the following data entries:

Table name: purchases

No alt text provided for this image

You might have noticed that consumers have made purchases in several months in some years. 

Assuming that 2015 is a reference year in your business, you might want to filter data according to 2015. For example, you might want to explore consumers based on their purchase dates:

All of these options are very confusing when addressed only in writing, so for convince, they are also graphically presented in Venn-Diagrams:

  •  All consumers that made a purchase on all dates;

No alt text provided for this image

  • All consumers that made a purchase only in 2015;

No alt text provided for this image

  • All consumers that made a purchase, excluding those that made a purchase only in 2015;

No alt text provided for this image

  • All consumers that made a purchase only in years other than 2015;

No alt text provided for this image

  • All consumers that made a purchase, excluding consumers that made a purchase only in years other than 2015;

No alt text provided for this image

  • All consumers that made a purchase only in both 2015 and other years;

No alt text provided for this image

  • All consumers that made a purchase, excluding consumers that made a purchase only in both 2015 and other years.

No alt text provided for this image


Here is the MS SQL syntax to get the right answers for all of the options:

No alt text provided for this image

Hope you enjoyed this article,

Nir





Nir, thanks for sharing! I posted your post in the group. I would love to see you there: https://bit.ly/4lViIHx

Like
Reply

Nir, thanks for sharing! My colleague would be happy to work with you. I highly recommend him. https://bit.ly/4raHtkl

Like
Reply

פירסמתי את הפוסט שלך בקבוצה אשמח לראות אותך שם🙂 https://chat.whatsapp.com/IHTFlHbcJZJDylwqf62EwA

Like
Reply

תודה רבה לך על השיתוף🙂 אני מזמין אותך לקבוצה שלי: הקבוצה מחברת בין ישראלים ואנשי העולם במגוון תחומים. https://chat.whatsapp.com/BubG8iFDe2bHHWkNYiboeU

Like
Reply

תודה רבה על השיתוף! אני מזמין אותך לקבוצה שלי שמחברת בין ישראלים לשאר העולם במגוון נושאים מטרת הקבוצה לשתף מידע, לשאול שאלות וליצור שיתופי פעולה: https://chat.whatsapp.com/BubG8iFDe2bHHWkNYiboeU

Like
Reply

To view or add a comment, sign in

More articles by Nir Ben Eliahu

  • Combining Jupyter with SQL & R

    This article explains how to set up Jupyter Notebook as a platform with MS SQL and R. The steps that are described in…

    3 Comments

Explore content categories