From the course: PostgreSQL: Advanced Queries
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Define values with CASE statements - PostgreSQL Tutorial
From the course: PostgreSQL: Advanced Queries
Define values with CASE statements
- [Instructor] In the previous chapter, we used a Case statement to help us group ranked data into Core Tiles. Let's take a closer look at the construct of a Case statement and see other ways where it could be useful in PostgreSQL. Now Case statements allow you to add an if, then, else logic into your queries. This allows the query to evaluate a condition and return a different value, depending on the results of that evaluation. A basic Case statement would look like this. First, it'll create a column in your query results, so treat it just like any other table column or function that you might add into the select clause of a query. Then, inside of the Case statement, you'll add when and then clauses. The when will be a condition that you'll want to evaluate and it either needs to be a true or false statement. The then portion will control what to respond with if the when condition is true. If the first when condition is…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.