Skip to main content
Users
CloudPortalLogin
  • Powered byPowered by
Introduction to Sitecore CDP
Data availability
Managing your account
Managing system settings
Managing guests
Batch segmentation
Data browser
Audience export
Dashboards
Developer center
AI in CDP
Glossary
  • Sitecore CDP
  • Introduction to batch segmentation
  • Using advanced mode in batch segmentation in Sitecore CDP
  • Write an SQL query in Sitecore CDP

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.

Before you begin

Create a segment in basic mode before you write your SQL query in advanced mode.

To create a segment by writing an SQL query:

  1. In the segment builder, under Segment rules, at the bottom right corner, click Advanced Mode

  2. 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.

    Note

    You 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.

  3. 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.

    Viewing fields and values on the Data tab in the SQL editor.
  4. 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.

  5. Click Save. You can no longer switch back to basic mode after you save a segment in advanced mode.

  6. 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.

  7. Schedule the segment to be included in your organization's nightly segment build. You must do this to use the segment within Sitecore CDP.

Do you have some feedback for us?

If you have suggestions for improving this article,

Privacy policySitecore Trust CenterCopyright © 1999-2026 Sitecore