Quotes help make search much faster. Example: "Practice Makes Perfect"

Monday, July 18, 2016

SQL: Table Transformation Lesson 17 Sample Solution


Instructions:
Write a query to count the number of low elevation airports by state where low elevation is defined as less than 1000 ft.

Be sure to alias the counted airports as count_low_elevation_airports.

Sample Solution:
SELECT state,
    COUNT(
      CASE
      WHEN elevation < 1000 THEN 1
        ELSE NULL
      END) as count_low_elevation_aiports
FROM airports
GROUP BY state;

1 comment:

  1. Running this query as is caused an error...formatting issue most likely.
    Cleaned it up a bit, run this:
    SELECT state,
    COUNT(CASE WHEN elevation < 1000 THEN 1 ELSE NULL END) as count_low_elevation_aiports
    FROM airports
    GROUP BY state;

    ReplyDelete


This is an example of scrolling text using Javascript.

Popular Posts