Skip to main content

SQL Use Cases

 


1. Age Group Segmentation

SQL Query

Select CustomerID, 

FirstName, 

Age,

Case

When Age < 18 Then 'Minor'

WHEN AGE BETWEEN 18 AND 40 THEN 'ADULT'

Else 'Senior'

END AS AgeGroup 

FROM [Customer DE- Age SQL]

2. Engagement Level

SQL Query

SELECT FirstName,

OpenCount, 

CASE

WHEN OPENCOUNT > 10 THEN 'HIGH'

WHEN OPENCOUNT BETWEEN 5 AND 10 THEN 'MEDIUM'

END AS ENGAMENTLEVEL

FROM [Customer DE- Age SQL]


*Missed to use the  ELSE 'Low' in query so the records shows "0" as record count which is not defined. And field also was not defined as per the “end engagement”


Check the last SQL query with target DE (combined) to find the right target DE


3. Greeting

SQL Query

SELECT FirstName,
Country,
CASE
WHEN COUNTRY = 'INDIA' THEN 'NAMASTE'
WHEN COUNTRY = 'USA' THEN 'HELLO'
ELSE 'HI'
END AS GREETING
FROM [Customer DE- Age SQL]




4. Status Mapping

SQL Query

SELECT FirstName, 
Status,
CASE 
 WHEN Status = 'A' THEN 'Active'
  WHEN Status = 'I' THEN 'Inactive'
   ELSE 'Unknown'
   END AS StatusLabel
   FROM [Customer DE- Age SQL]



5. Purchase Segmentation

SQL Query

SELECT FirstName,
CASE
 WHEN PurchaseAmount > 2000 THEN 'Premium'
 WHEN PurchaseAmount BETWEEN 500 AND 2000 THEN 'Standard'
 ELSE 'Low Value'
 END AS CustomerType
 FROM [Customer DE- Age SQL]



6. Re-engagement

SQL Query

SELECT FirstName,
CASE
 WHEN OpenCount = 0 THEN 'Re-engage'
  ELSE 'Active User'
  END AS CampaignType
  FROM [Customer DE- Age SQL]


7. Youth Campaign

SQL Query

SELECT FirstName,

CASE

 WHEN Age < 25 THEN 'Youth Campaign'

  ELSE 'General Campaign'

  END AS Campaign

  FROM [Customer DE- Age SQL]


8. VIP Segment

SQL Query

SELECT FirstName,

CASE

 WHEN PurchaseAmount > 1000 AND OpenCount > 10 THEN 'VIP'

  ELSE 'Normal'

  END AS Segment

  From [Customer DE- Age SQL]



9. Email Strategy

SQL Query

SELECT FirstName,

Case

 WHEN OpenCount > 10 THEN 'Daily Emails'

  WHEN OpenCount BETWEEN 5 AND 10 THEN 'Weekly Emails'

   ELSE 'Monthly Emails'

   END AS EmailStrategy

   From [Customer DE- Age SQL]


10. Risk Identification

SQL Query

SELECT FirstName,

CASE

 WHEN OpenCount < 3 AND PurchaseAmount < 500 THEN 'At Risk'

 ELSE 'Safe'

 END AS RiskLevel

 From [Customer DE- Age SQL]



** Tried entering 3 combined SQL Query and target DE with three fields

Select

FirstName,

CASE

 WHEN Age < 18 THEN 'Minor'

  WHEN Age BETWEEN 18 AND 40 THEN 'Adult'

   ELSE 'Senior'

   END AS AgeGroup,

   

   CASE

   WHEN OpenCount > 10 THEN 'High'

    WHEN OpenCount BETWEEN 5 AND 10 THEN 'Medium'

     ELSE 'Low'

     END AS Engagement,

    

     CASE

      WHEN Country = 'India' THEN 'Namaste'

       WHEN Country = 'USA' THEN 'Hello'

       ELSE 'Hi'

       END AS Greeting

       From [Customer DE- Age SQL]











Comments

Popular posts from this blog

A/B Testing

Confluence link 1:  https://elearningit24.atlassian.net/wiki/external/MzA3YWUxNjI3YzBkNGZiZmFlZTc1ZGIzYmU1ZmM1MmQ   What is A/B Testing? A/B testing, also known as split testing , is a controlled experiment where two versions of a webpage, email, ad, or any digital asset are tested against each other to determine which one performs better. Why? Higher open rates Better Engagement Increased Sales and Lead conversion Reduced unsubscribed rates Date Driven- No assumption & Proven Results Test Type Subject Line Email Content Area From Name Send Date & Time Pre Header   Email Test Template: Friendly and Personalised Straight to the point & Action Oriented Confluence Link 2:  https://elearningit24.atlassian.net/wiki/external/NDk0Zjg0ODk3YjAwNDI5ZjkxOTVmMTAxNTQ3ZjlhNmQ Subject Line A/B Test: A/B Testing Use Case: Optimizing Email Subject Lines for Higher Open Rates Scenario- Subject Line: A company wants to increase the open rates of its promotional emails in Sa...

Email Marketing Campaings

Use Cases of Standard Data Extensions 1. Customer Data Storage Scenario : A retail business wants to store customer information, such as names, email addresses, and purchase history, for email marketing campaigns. Solution : Use a standard data extension to store and manage customer data securely and efficiently. Data Extension Structure Field Name Data Type Length Required Primary Key SubscriberKey Text 50 Yes Yes FirstName Text 50 Yes No LastName Text 50 Yes No EmailAddress EmailAddress N/A Yes No PurchaseHistory Decimal N/A No No Sample Records SubscriberKey FirstName LastName EmailAddress PurchaseHistory 001 John Doe john.doe@example.com 1500.50 002 Jane Smith jane.smith@example.com 200.00 https://mc.s8.exacttarget.com/cloud/#app/Email/C12/Default.aspx?entityType=none&entityID=0&ks=ks%23Subscribers

SQl Query

  Workflow: Journey Builder> Automation Studio> New Automation Enter Query: Drag and drop Schedule in  Start with a Starting Source and the SQL Query> Choose Query> Create New Query Activity> Name your file and add your query (Field name thats part of the DE you create separately- Example: FirstName, LastName, Subscriber Key) Create a new DE in Email Studio with the query field> Select The test DE which was created: Select Target DE and Save & Run Workflow: Select All Activities and Run Workflow: Activity Details: Run Completed with updated DE Edit/ add another query: Copy Source DE and create a new DE with same fields that we are running in SQL: Run the updated SQL Query added Activity and DE updated with Records: Completed Status: Received error: When the Query field and the DE created field does not match When an existing Query is being run, if we try to run another query Fixed the error by matching same field Waiting for existing query to complete