Wrapping up!

Data Manipulation in Snowflake

Jake Roach

Field Data Engineer

Data manipulation in Snowflake

$$

      CASE Statements

                Manipulate and transform data based on certain conditions.

      Subqueries

                 Leverage the results of a query in another.

      Common Table Expressions

                Define a temporary result set for use in a main query.

Data Manipulation in Snowflake

Conditional logic

SELECT
    todays_date,
    temperature,
    status,
    CASE
        WHEN temperature > 70 AND status NOT IN ('Rain', 'Wind') THEN 'Beach'
        WHEN temperature BETWEEN 45 AND 70 AND status = 'Sun' THEN 'Sports'
        WHEN temperature <= 32 OR status = 'Snow' THEN 'Skiing'
        ELSE 'Stay In'
    END AS activity
FROM weather;

Conditional logic can be combined with things like aggregation functions.

Data Manipulation in Snowflake

Subqueries

Logical process of manipulating data in a more readable and modular manner with subqueries

SELECT
    month_num,
    AVG(differential) AS avg_differential
    MIN(differential) AS most_differential
FROM (
    SELECT
        month_num,
        windchill - temperature AS differential
    FROM weather
    WHERE 
        season = 'Winter' AND
        temperature < 32
)
GROUP BY month_num;
Data Manipulation in Snowflake

Common Table Expressions

WITH at_risk AS (
    SELECT
        student_id
        course_name,
        teacher_name,
        grade
    FROM student_courses
    WHERE grade < 70 AND is_required
)

SELECT
    students.student_name,
    at_risk.*
FROM at_risk
JOIN students ON at_risk.student_id = students.id;

Common Table Expressions (CTE's) temporarily store the results of a query to eventually be used by another query

$$

  • Structure queries to be more readable, modular
  • Define and use multiple CTE's
Data Manipulation in Snowflake

Let's practice!

Data Manipulation in Snowflake

Preparing Video For Download...