Before you start
You need Workbench and a running SQL engine. Every example includes its own input rows. No catalog, files, credentials, or external data is needed. These queries create no stored tables. Copy the SQL into Workbench and run the statements in order. Compare the result with the table below the query.WITH names input data for one statement only. Each example can run on its own.
1. Extract a year
Which year contains each event?
DATE_PART reads a calendar field.
Change one thing: Use month instead of year. Expect 1, 1, and 2.
2. Extract a day
On which day of the month did each event occur?
The day field is the day within the month.
Change one thing: Use month instead. Expect 1, 1, and 2.
3. Filter a date range
Which events occurred in January?
A half-open range includes the start and excludes the next period.
Change one thing: Use February boundaries. Only ID 3 appears.
4. Group by month
What are monthly sales?
This dataset contains one year. Include year when data spans several years.
Change one thing: Use COUNT(*) instead of SUM(amount). Expect January 2 and February 1.
5. Find month boundaries
What is the first day of each event month?
TIMESTAMP_NTZ gives this truncation a timestamp without time-zone conversion.
Change one thing: Use year instead of month. All rows return 2024-01-01.
6. Add an interval
What is the following calendar day?
An interval expresses a calendar offset.
Change one thing: Change 1 to 2. Expect January 17, January 22, and February 5.