Write and run an SQL query in Sitecore CDP
How to write and run an SQL query to create a segment (Sitecore CDP).
You can switch to advanced mode to write a complex SQL query if you know SQL and are familiar with the Sitecore CDP data model. We recommend switching to advanced mode if you want to apply regression logic, quartiles, and other advanced segmentation capabilities. Before you write your SQL query, you must start to create a segment in basic mode before you switch to advanced mode.
Write an SQL query to create a segment
To create a segment by writing an SQL query:
In the segment builder, click Advanced Mode. A confirmation window displays.
Click Yes. The SQL editor displays. Sitecore CDP converts the segment you created in basic mode into SQL statements that you can further edit.
Note
You must follow the rules for writing SQL queries in the SQL editor as you write your SQL query.
If you do not want to copy and paste values, fields, or code snippets, you can now run the SQL query.
To copy and paste values and fields, on the Data tab, click the arrow
icon on the entity block to see the available fields and values you can include in the SQL query. Click the copy
icon next to the field or value and paste it into the SQL editor.
To copy code snippets, on the Snippets tab, click the entity block, click the Copy link next to the code you want to copy, and paste the code snippet into the SQL editor.
Schedule the segment to be included in your organization's nightly segment build. You must do this to use the segment within Sitecore CDP.
Run an SQL query
After you write an SQL query, you can run the query to return the guest_ref
count and view a sample of 10 guest_ref
records that are included in the segment.
To run an SQL query:
In the segment builder, click Run. Sitecore CDP displays the rows returned and the time it took to run the query, as shown in the following image:
Click View sample. The View Execution Sample window displays a maximum of 10
guest_refs
that are included in the segment results.Click the new window
icon to open the guest profile in a separate browser window.