Write an SQL query in 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.
Create a segment in basic mode before you write your SQL query in advanced mode.
To create a segment by writing an SQL query:
-
In the segment builder, under Segment rules, at the bottom right corner, click Advanced Mode
-
In the confirmation window, click Yes, switch. The SQL editor displays. Sitecore CDP converts the segment you created in basic mode into SQL statements that you can further edit.
NoteYou must follow the rules for writing SQL queries in the SQL editor as you write your SQL query.
Amazon Athena, the query service that enables the SQL editor, has query limitations on complexity and resource usage. Simplify your queries where possible to avoid execution failures.
-
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
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.
-
Click Save. You can no longer switch back to basic mode after you save a segment in advanced mode.
-
To calculate the audience size of the segment and view a guest sample, go to the Calculate audience tab or calculate it in the segment builder.
-
Schedule the segment to be included in your organization's nightly segment build. You must do this to use the segment within Sitecore CDP.