EasySQL
Filter Flights by Price Range
SQLDatabases
Write a SQL query that returns all flights with a price **between $80 and
$250 inclusive**, showing the route and price, ordered by price ascending.
Table: flights
| id | route | price | airline |
|---|---|---|---|
| 1 | NYC-LAX | 250 | United |
| 2 | NYC-CHI | 120 | Delta |
| 3 | LAX-SFO | 80 | Southwest |
| 4 | CHI-MIA | 320 | American |
| 5 | SFO-SEA | 90 | Alaska |
| 6 | NYC-BOS | 55 | JetBlue |
Expected output (columns: route, price)
LAX-SFO|80
SFO-SEA|90
NYC-CHI|120
NYC-LAX|250
BETWEEN a AND bis inclusive on both ends — equivalent to>= a AND <= b.
Sample tests
Test #14 of 6 flights fall within the range
Input: "CREATE TABLE flights (id INTEGER, route TEXT, price INTEGER, airline TEXT);\nINSERT INTO flights VALUES\n (1, 'NYC-LAX', 250, 'United'),\n (2, 'NYC-CHI', 120, 'Delta'),\n (3, 'LAX-SFO', 80, 'Southwest'),\n (4, 'CHI-MIA', 320, 'American'),\n (5, 'SFO-SEA', 90, 'Alaska'),\n (6, 'NYC-BOS', 55, 'JetBlue');"
Output: "LAX-SFO|80\nSFO-SEA|90\nNYC-CHI|120\nNYC-LAX|250"