Skip to content

Update query-language.md #6555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/api/public-api/query-language.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ Another way to think of this scenario would be:
Here's how you could do that in Segment's query language:

```sql
event(Shoes Bought).where( property(price) >= 100 ).within(7 days).count() >= 1
event('Shoes Bought').where( property('price') >= 100 ).within(7 days).count() >= 1
```

#### Bought and returned
Expand All @@ -435,10 +435,10 @@ This example collects:
- and the user performed the `Shoes Returned` event at least once, five days after the `Shoes Bought` event

```sql
event(Shoes Bought).where(
property(price) >= trait(avg_spend)
event('Shoes Bought').where(
property('price') >= trait('avg_spend')
AND
event(Shoes Returned).within(parent: 5 days).count() >= 1
event('Shoes Returned').within(parent: 5 days).count() >= 1
).within(30 days).count() >= 1
```

Expand All @@ -447,31 +447,31 @@ event(‘Shoes Returned’).within(parent: 5 days).count() >= 1
This example collects all users who did not perform the `Shoes Bought` event at least once and don't have a `total_spend` trait with a value greater than `200`:

```sql
NOT ( event(Shoes Bought).count() >= 1 AND trait(total_spend) > 200 )
NOT ( event('Shoes Bought').count() >= 1 AND trait('total_spend') > 200 )
```

#### Bought with minimum total spend

This example collects all accounts where all associated users performed the `Shoes Bought` event at least once and have a `total_spend` trait greater than `200`:

```sql
ALL ( event(Shoes Bought).count() >= 1 AND trait(total_spend) > 200 )
ALL ( event('Shoes Bought').count() >= 1 AND trait('total_spend') > 200 )
```

#### No users bought at least once

This example collects all accounts where no associated users performed the `Shoes Bought` event at least once:

```sql
ALL NOT event(Shoes Bought).count() >= 1
ALL NOT event('Shoes Bought').count() >= 1
```

#### Any users bought at least once

This example collects all accounts where any associated users performed the `Shoes Bought` event at least once:

```sql
ANY event(Shoes Bought).count() >= 1
ANY event('Shoes Bought').count() >= 1
```

### Computed Traits
Expand All @@ -487,15 +487,15 @@ Another way to think of this would be:
Here's how you could do that in Segment's query language:

```sql
event(Shoes Bought).within(30 days).avg(property(spend))
event('Shoes Bought').within(30 days).avg(property('spend'))
```

#### Calculate minimum spend

This example calculates the minimum spend for each user, based on all `Shoes Bought` events, where the price was greater than `100` and the brand was `My_Brand`:

```sql
event(Shoes Bought).where( property(price) > 100 AND property(brand) = My Brand ).min(property(spend))
event('Shoes Bought').where( property('price') > 100 AND property('brand') = 'My Brand' ).min(property('spend'))
```

#### Calculate first seen spend
Expand Down