Skip to content

Commit bbda000

Browse files
forstisabellamarkzegarelli
andauthored
Apply suggestions from code review [netlify-build]
Co-authored-by: markzegarelli <[email protected]>
1 parent d7ec2a7 commit bbda000

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/connections/storage/warehouses/redshift-useful-sql.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
title: Useful SQL Queries for Redshift
33
---
4-
Below you'll find a library of some of the most useful SQL queries customers use in their Redshift warehouses. You can run these right in your Redshift instance with little to no modification.
4+
Below you'll find a library of some of the most useful SQL queries customers use in their Redshift warehouses. You can run these in your Redshift instance with little to no modification.
55

66
> success "Ways to improve query speed"
7-
> If you're looking to improve the speed of your queries, check out Segment's [Speeding Up Redshift Queries](/docs/connections/storage/warehouses/redshift-tuning/) page!
7+
> If you're looking to improve the speed of your queries, check out Segment's [Speeding Up Redshift Queries](/docs/connections/storage/warehouses/redshift-tuning/) page.
88
99
You can use SQL queries for the following tasks:
1010
- [Tracking events](#tracking-events)
@@ -54,7 +54,7 @@ That SQL query returns a table that looks like this:
5454
![](images/sql-redshift-table-1.jpg)
5555

5656
But why are there columns in the table that weren't a part of the track call, like `event_id`?
57-
This is because the track method (for client-side libraries) automatically includes additional properties of the event, like `event_id`, `sent_at`, and `user_id`!
57+
This is because the track method (for client-side libraries) includes additional properties of the event, like `event_id`, `sent_at`, and `user_id`!
5858

5959
### Grouping events by day
6060
If you want to know how many orders were completed over a span of time, you can use the `date()` and `count` function with the `sent_at` timestamp:
@@ -65,15 +65,15 @@ from initech.tracks
6565
where event = 'completed_order'
6666
group by date
6767
```
68-
That query will return a table like this:
68+
That query returns a table like this:
6969

7070
| date | count |
7171
| ---------- | ----- |
7272
| 2021-12-09 | 5 |
7373
| 2021-12-08 | 3 |
7474
| 2021-12-07 | 2 |
7575

76-
If you wanted to see how many pants and shirts were sold on each of those dates, you can query that using case statements:
76+
To see the number of pants and shirts that were sold on each of those dates, you can query that using case statements:
7777

7878
```sql
7979
select date(sent_at) as date,
@@ -93,19 +93,19 @@ That query returns a table like this:
9393
| 2021-12-07 | 2 | 0 |
9494

9595

96-
## Defining sessions
96+
## Define sessions
9797
Segment’s API does not impose any restrictions on your data with regard to user sessions.
9898

9999
Sessions aren’t fundamental facts about the user experience. They’re stories Segment builds around the data to understand how customers actually use the product in their day-to-day lives. And since Segment’s API is about collecting raw, factual data, there's no API for collecting sessions. Segment leaves session interpretation to SQL partners, which let you design how you measure sessions based on how customers use your product.
100100

101-
For more on why Segment doesn't collect session data at the API level, [check out a blog post here](https://segment.com/blog/facts-vs-stories-why-segment-has-no-sessions-api/)!
101+
For more on why Segment doesn't collect session data at the API level, [check out a blog post here](https://segment.com/blog/facts-vs-stories-why-segment-has-no-sessions-api/){:target="_blank"}.
102102

103103
### How to define user sessions using SQL
104-
Each of Segment's SQL partners allows you to define sessions based on your specific business needs. With [Looker](https://looker.com), for example, you can take advantage of their persistent derived tables and LookML modeling language to layer sessionization on top of your Segment SQL data. Segment recommends [checking out Looker's approach here](https://segment.com/blog/using-sql-to-define-measure-and-analyze-user-sessions/)!
104+
Each of Segment's SQL partners allow you to define sessions based on your specific business needs. With [Looker](https://looker.com){:target="_blank"}, for example, you can take advantage of their persistent derived tables and LookML modeling language to layer sessionization on top of your Segment SQL data. Segment recommends [checking out Looker's approach here](https://segment.com/blog/using-sql-to-define-measure-and-analyze-user-sessions/).
105105

106-
For defining sessions with raw SQL, a great query and explanation comes from [Mode Analytics](https://mode.com).
106+
To define sessions with raw SQL, a great query and explanation comes from [Mode Analytics](https://mode.com).
107107

108-
Here’s the query to make it happen, but definitely check Mode Analytics' [blog post](https://blog.modeanalytics.com/finding-user-sessions-sql/) as well. They walk you through the reasoning behind the query, what each portion accomplishes, how you can tweak it to suit your needs, and what kind of further analysis you can do on top of it.
108+
Here’s the query to make it happen, but read Mode Analytics' [blog post](https://blog.modeanalytics.com/finding-user-sessions-sql/) for more information. Mode walks you through the reasoning behind the query, what each portion accomplishes, how you can tweak it to suit your needs, and the kinds of further analysis you can add on top of it.
109109

110110
```sql
111111
-- Finding the start of every session
@@ -135,7 +135,7 @@ SELECT *,
135135
) final
136136
```
137137

138-
## Identifying users
138+
## Identify users
139139

140140
### Historical traits
141141

@@ -171,13 +171,13 @@ This SQL query returns a table of Bob's account information, with each entry rep
171171
| bob123 | [email protected] | Premium | 2021-12-20 19:44:03 |
172172
| bob123 | [email protected] | Basic | 2021-12-18 17:48:10 |
173173

174-
If you want to see what your users looked like at a previous point in time, that data is right there in your `identifies` table! (To get this table for your users, replace ‘initech’ in the SQL query with your source slug).
174+
If you want to see what your users looked like at a previous point in time, you can find that data in the `identifies` table. To get this table for your users, replace ‘initech’ in the SQL query with your source slug.
175175

176176
But what if you only want to see the most recent state of the user? Luckily, you can convert the `identifies` table into a distinct users table by taking the most recent identify call for each account.
177177

178-
### Converting the identifies table into a users table
178+
### Convert the identifies table into a users table
179179

180-
The following query will return your `identifies` table:
180+
The following query returns the `identifies` table:
181181

182182
```sql
183183
select *

0 commit comments

Comments
 (0)