---
schema_version: "1"
id: 36f7c5759ba2ee2c1369b98d91ebd3eef12d98abb53769fa46b00883e603a183
title: SQL Use Cases for Insights Data 360
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/data/264-0-0/c360_a_calculated_insights_use_cases.md
canonical_url: https://help.salesforce.com/s/articleView?id=data.c360_a_calculated_insights_use_cases.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 5e9d432cab37925de90403cc1e3cdfd5a98c0ef018e17bc15da4f73703e9a667
description: There are several useful code blocks when creating insights in Data 360.
products:
  - Data 360
release: "264"
---
# SQL Use Cases for Insights Data 360

There are several useful code blocks when creating insights in Data 360.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>All Editions</strong> supported by Data 360. See <a href="https://help.salesforce.com/s/articleView?id=data.c360_a_dc_editions.htm&amp;language=en_US" target="_blank">Data 360 edition availability</a>.</td></tr></tbody></table>

Use these code block examples to successfully create your Calculated Insights.

![Using UnifiedIndividalID as a Dimension](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-data-data_cloud-264-0-0-production-enus/f3569962-3c9b-4f83-9d0c-b6a574e785da/images/icon_example.png)

Using UnifiedIndividalID as a Dimension

```sql
SELECT
COUNT(EmailEngagement__dlm.Id__c) as email_engagement_count__c,
UnifiedIndividual__dlm.Id__c as customer_id__c
FROM
 EmailEngagement__dlm
JOIN
 IndividualIdentityLink__dlm
ON
 EmailEngagement__dlm.IndividualId__c = IndividualIdentityLink__dlm.SourceRecordId__c
JOIN
 UnifiedIndividual__dlm
ON
 UnifiedIndividual__dlm.Id__c = IndividualIdentityLink__dlm.UnifiedRecordId__c
GROUP BY
customer_id__c
```

![Group customers based on Recency, Frequency, and Monetary \[RFM\] Score](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-data-data_cloud-264-0-0-production-enus/f3569962-3c9b-4f83-9d0c-b6a574e785da/images/icon_example.png)

Group customers based on Recency, Frequency, and Monetary \[RFM\] Score

```sql
SELECT sub2.cust_id__c as id__c,
FIRST(sub2.rfm_recency__c*100 + sub2.rfm_frequency__c*10 +sub2.rfm_monetary__c) as rfm_combined__c,
FIRST(sub2.rfm_recency__c) as Recency__c,
FIRST(sub2.rfm_frequency__c) as Frequency__c,
FIRST(sub2.rfm_monetary__c) as Monetary__c
From (
 select UnifiedIndividual__dlm.Id__c as cust_id__c,
 ntile(4) over (order by MAX(SALESORDER__dlm.checkout_date__c)) as rfm_recency__c,
 ntile(4) over (order by SUM(SALESORDER__dlm.orderid__c)) as rfm_frequency__c,
 ntile(4) over (order by avg(SALESORDER__dlm.grand_total_amount__c)) as rfm_monetary__c
 FROM SALESORDER__dlm
LEFT JOIN
IndividualIdentityLink__dlm
on
SALESORDER__dlm.partyid__c=IndividualIdentityLink__dlm.SourceRecordId__c
LEFT Join
UnifiedIndividual__dlm
on
UnifiedIndividual__dlm.Id__c=IndividualIdentityLink__dlm.UnifiedRecordId__c
 group by cust_id__c
) as sub2
group by sub2.cust_id__c
```

![Count of email opened by Unified Individual](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-data-data_cloud-264-0-0-production-enus/f3569962-3c9b-4f83-9d0c-b6a574e785da/images/icon_example.png)

Count of email opened by Unified Individual

```sql
SELECT COUNT( EmailEngagement__dlm.Id__c ) as email_count__c,
UnifiedIndividual__dlm.Id__c as customer_id__c
FROM
EmailEngagement__dlm
LEFT JOIN
 IndividualIdentityLink__dlm
ON
 IndividualIdentityLink__dlm.SourceRecordId__c = EmailEngagement__dlm.IndividualId__c
 and EmailEngagement__dlm.EngagementChannelActionId__c = 'Open'
JOIN
 UnifiedIndividual__dlm
ON
 UnifiedIndividual__dlm.Id__c = IndividualIdentityLink__dlm.UnifiedRecordId__c
GROUP BY
customer_id__c
```

![Rank customers by repeat purchase by product category](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-data-data_cloud-264-0-0-production-enus/f3569962-3c9b-4f83-9d0c-b6a574e785da/images/icon_example.png)

Rank customers by repeat purchase by product category

```sql

SELECT
FIRST(SubQuery2.highest_purcahased_rank__c) as purchase_rank__c, 
SubQuery2.CustomerId__c as UnifiedCustomerID__c, 
SubQuery2.product_category__c as ProdSubCategory__c
FROM
    (
      SELECT 
            RANK() OVER ( PARTITION BY SubQuery1.id__c 
            order by (SubQuery1.product_purchase_count__c) desc ) 
            as highest_purcahased_rank__c, 
            SubQuery1.id__c as CustomerId__c, 
            SubQuery1.product_category__c as product_category__c
            FROM
                (
                SELECT 
                     UnifiedIndividual__dlm.Id__c as id__c,
                     PRODUCT__dlm.product_subcategory__c as product_category__c,
                     COUNT(PRODUCT__dlm.product_sk_u__c ) as product_purchase_count__c
                            FROM
                            PRODUCT__dlm
                            JOIN
                            SALESORDERPRODUCT__dlm
                            ON PRODUCT__dlm.productid__c=SALESORDERPRODUCT__dlm.productid__c
                            JOIN
                            SALESORDER__dlm 
                            ON SALESORDER__dlm.orderid__c=SALESORDERPRODUCT__dlm.orderid__c
                            LEFT JOIN
                            IndividualIdentityLink__dlm
                            on
                            SALESORDER__dlm.partyid__c=IndividualIdentityLink__dlm.SourceRecordId__c
                            LEFT Join
                            UnifiedIndividual__dlm
                            on
                           UnifiedIndividual__dlm.Id__c=IndividualIdentityLink__dlm.UnifiedRecordId__c
                             group by 
                             id__c, product_category__c
                ) as SubQuery1
    ) as SubQuery2
group by 
UnifiedCustomerID__c, ProdSubCategory__c
```