IF in the SELECT

Last modified: October 10, 2019

Contribute to Data School

We are actively working on this chapter. We are looking for two types of contributions:

  1. Help writing this chapter
  2. Share your story about working through this problem at work

Please reach out to @Matt David on our slack to discuss what you want to contribute.

Data School wants a comprehensive post showing how to use IF in the SELECT statement and choose output value based on column values. Please use stack overflow to understand the many variations: https://stackoverflow.com/questions/5951157/if-in-select-statement-choose-output-value-based-on-column-values

The structure of the post should be

  • Answer the question simply (provide sql query when appropriate)
  • Define example scenario we will be using (use a familiar dataset: facebook friends, Amazon store, Uber riders, etc)
    • Provide a small table
  • Use images to show what is happening
    • link to other Data School pages/images where appropriate (joins, aggregations, subqueries, window functions, case when)
  • Demonstrate in detail with SQL
  • Recap why this was important to answer the question

Written by:
Reviewed by:

Next – Importing Data from CSV in PostgreSQL

Get new data chapters sent right to your Inbox