Quick Overview

Write a SQL query that joins satellite image metadata to sensor details, keeps only images with valid latitude and longitude, and returns the newest captures first. It tests inclusive range filters, how NULL values behave in a WHERE clause, and deterministic ordering with a unique tiebreaker.

List satellite images with valid coordinates joined to their sensors, newest first

Company: Intel

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

An imagery pipeline writes one metadata row per captured satellite image to `satellite_images`, and each row references the sensor that captured it in `sensors`. Coordinates are stored as received from upstream and are not validated on write, so some rows carry impossible or missing values. Return each image with valid coordinates (`latitude` between -90 and 90, `longitude` between -180 and 180) joined with its sensor, as `image_id`, `image_name`, `sensor_name`, `sensor_type`, `latitude`, `longitude`, `capture_time`, `resolution_meters`, `cloud_cover_pct`, `file_size_mb`. Order by `capture_time` descending, then `image_id` ascending. ```hint Edge rows Before writing the filter and the sort, decide what should happen to an image that sits exactly on a coordinate limit, one with a missing coordinate, and two images captured at the same moment. ``` ### Input Table(s) `sensors` (primary key `sensor_id`) | Column | Type | Meaning | |---|---|---| | sensor_id | INT | Sensor identifier | | sensor_name | VARCHAR | Sensor name | | sensor_type | VARCHAR | Kind of sensor, for example 'optical', 'radar' or 'thermal' | `satellite_images` (primary key `image_id`) | Column | Type | Meaning | |---|---|---| | image_id | INT | Image identifier | | image_name | VARCHAR | Image name | | sensor_id | INT | Sensor that captured the image; references `sensors.sensor_id` | | latitude | DECIMAL(9,6) | Latitude of the image center in degrees; may be out of range or NULL | | longitude | DECIMAL(9,6) | Longitude of the image center in degrees; may be out of range or NULL | | capture_time | TIMESTAMP | When the image was captured | | resolution_meters | DECIMAL(8,2) | Ground resolution in meters per pixel | | cloud_cover_pct | DECIMAL(5,2) | Share of the image covered by cloud, in percent | | file_size_mb | DECIMAL(10,2) | File size in megabytes | ### Output Contract - One row per image with valid coordinates, with these columns in this order: `image_id`, `image_name`, `sensor_name`, `sensor_type`, `latitude`, `longitude`, `capture_time`, `resolution_meters`, `cloud_cover_pct`, `file_size_mb`. - Order by `capture_time` descending, then `image_id` ascending. `image_id` is unique, so the order is fully determined. - Return values as stored, with no rounding or reformatting. ### Example `sensors` | sensor_id | sensor_name | sensor_type | |---|---|---| | 1 | OPT-A | optical | | 2 | SAR-B | radar | | 3 | IR-C | thermal | `satellite_images` | image_id | image_name | sensor_id | latitude | longitude | capture_time | resolution_meters | cloud_cover_pct | file_size_mb | |---|---|---|---|---|---|---|---|---| | 1001 | coast_0412 | 1 | 37.774900 | -122.419400 | 2024-04-12 10:15:00 | 0.50 | 12.30 | 845.20 | | 1002 | delta_0412 | 2 | 23.810300 | 90.412500 | 2024-04-12 10:15:00 | 3.00 | 0.00 | 1210.75 | | 1003 | glitch_0413 | 1 | 95.000000 | 10.000000 | 2024-04-13 08:00:00 | 0.50 | 40.00 | 790.00 | | 1004 | pole_0413 | 3 | 90.000000 | 0.000000 | 2024-04-13 06:30:00 | 10.00 | 85.50 | 300.40 | | 1005 | dateline_0411 | 2 | -16.500000 | -180.000000 | 2024-04-11 22:45:00 | 3.00 | 5.25 | 1100.00 | | 1006 | badlon_0414 | 3 | 10.000000 | 181.500000 | 2024-04-14 09:00:00 | 10.00 | 20.00 | 310.00 | | 1007 | nolon_0412 | 1 | 45.000000 | NULL | 2024-04-12 11:00:00 | 0.50 | 3.00 | 820.00 | Expected output: | image_id | image_name | sensor_name | sensor_type | latitude | longitude | capture_time | resolution_meters | cloud_cover_pct | file_size_mb | |---|---|---|---|---|---|---|---|---|---| | 1004 | pole_0413 | IR-C | thermal | 90.000000 | 0.000000 | 2024-04-13 06:30:00 | 10.00 | 85.50 | 300.40 | | 1001 | coast_0412 | OPT-A | optical | 37.774900 | -122.419400 | 2024-04-12 10:15:00 | 0.50 | 12.30 | 845.20 | | 1002 | delta_0412 | SAR-B | radar | 23.810300 | 90.412500 | 2024-04-12 10:15:00 | 3.00 | 0.00 | 1210.75 | | 1005 | dateline_0411 | SAR-B | radar | -16.500000 | -180.000000 | 2024-04-11 22:45:00 | 3.00 | 5.25 | 1100.00 | Image 1003 has a latitude of 95 and image 1006 a longitude of 181.5, so both are dropped, and image 1007 is dropped because its longitude is missing. Images 1004 and 1005 sit exactly on a limit and are kept. Images 1001 and 1002 share a capture time, so the smaller `image_id` comes first. ### Constraints and Clarifications - `sensors` has at most 100 rows and `satellite_images` at most 10,000 rows. - Valid coordinates are `latitude` in [-90, 90] and `longitude` in [-180, 180], limits included. Stored values can fall outside these ranges or be NULL, and such images are excluded. - `cloud_cover_pct` is 0.00 to 100.00 and `resolution_meters` is positive. - Every `sensor_id` in `satellite_images` references a valid sensor. - `capture_time` is never NULL, and several images can share the same `capture_time`.

Overview: Write a SQL query that joins satellite image metadata to sensor details, keeps only images with valid latitude and longitude, and returns the newest captures first. It tests inclusive range filters, how NULL values behave in a WHERE clause, and deterministic ordering with a unique tiebreaker.

An imagery pipeline writes one metadata row per captured satellite image to `satellite_images`, and each row references the sensor that captured it in `sensors`. Coordinates are stored as received from upstream and are not validated on write, so some rows carry impossible or missing values. Return each image with valid coordinates (`latitude` between -90 and 90, `longitude` between -180 and 180) joined with its sensor, as `image_id`, `image_name`, `sensor_name`, `sensor_type`, `latitude`, `longitude`, `capture_time`, `resolution_meters`, `cloud_cover_pct`, `file_size_mb`. Order by `capture_time` descending, then `image_id` ascending. ### Input Tables `sensors` (primary key `sensor_id`) | Column | Type | Meaning | |---|---|---| | sensor_id | INTEGER | Sensor identifier | | sensor_name | VARCHAR(50) | Sensor name | | sensor_type | VARCHAR(20) | Kind of sensor, for example 'optical', 'radar' or 'thermal' | `satellite_images` (primary key `image_id`) | Column | Type | Meaning | |---|---|---| | image_id | INTEGER | Image identifier | | image_name | VARCHAR(100) | Image name | | sensor_id | INTEGER | Sensor that captured the image; references `sensors.sensor_id` | | latitude | DECIMAL(9,6) | Latitude of the image center in degrees; may be out of range or NULL | | longitude | DECIMAL(9,6) | Longitude of the image center in degrees; may be out of range or NULL | | capture_time | TIMESTAMP | When the image was captured | | resolution_meters | DECIMAL(8,2) | Ground resolution in meters per pixel | | cloud_cover_pct | DECIMAL(5,2) | Share of the image covered by cloud, in percent | | file_size_mb | DECIMAL(10,2) | File size in megabytes | ### Output Contract - One row per image with valid coordinates, with these columns in this order: `image_id`, `image_name`, `sensor_name`, `sensor_type`, `latitude`, `longitude`, `capture_time`, `resolution_meters`, `cloud_cover_pct`, `file_size_mb`. - Order by `capture_time` descending, then `image_id` ascending. `image_id` is unique, so the order is fully determined. - Return values as stored, with no rounding or reformatting. ### Constraints and Clarifications - `sensors` has at most 100 rows and `satellite_images` at most 10,000 rows. - Valid coordinates are `latitude` in [-90, 90] and `longitude` in [-180, 180], limits included. Stored values can fall outside these ranges or be NULL, and such images are excluded. - `cloud_cover_pct` is 0.00 to 100.00 and `resolution_meters` is positive. - Every `sensor_id` in `satellite_images` references a valid sensor. - `capture_time` is never NULL, and several images can share the same `capture_time`.

Tables

sensors(sensor_id INTEGER, sensor_name VARCHAR(50), sensor_type VARCHAR(20))

satellite_images(image_id INTEGER, image_name VARCHAR(100), sensor_id INTEGER, latitude DECIMAL(9,6), longitude DECIMAL(9,6), capture_time TIMESTAMP, resolution_meters DECIMAL(8,2), cloud_cover_pct DECIMAL(5,2), file_size_mb DECIMAL(10,2))

Hints

  1. Before writing the filter and the sort, decide what should happen to an image that sits exactly on a coordinate limit, one with a missing coordinate, and two images captured at the same moment.
  2. The result has one row per qualifying image. The sensors table only supplies `sensor_name` and `sensor_type` for those images.
IntelData ScientisteasyData Manipulation (SQL/Python)

Satellite Images with Valid Coordinates

An imagery pipeline writes one metadata row per captured satellite image to satellite_images, and each row references the sensor that captured it in sensors. Coordinates are stored as received from upstream and are not validated on write, so some rows carry impossible or missing values.

Return each image with valid coordinates (latitude between -90 and 90, longitude between -180 and 180) joined with its sensor, as image_id, image_name, sensor_name, sensor_type, latitude, longitude, capture_time, resolution_meters, cloud_cover_pct, file_size_mb. Order by capture_time descending, then image_id ascending.

Input Tables

sensors (primary key sensor_id)

ColumnTypeMeaning
sensor_idINTEGERSensor identifier
sensor_nameVARCHAR(50)Sensor name
sensor_typeVARCHAR(20)Kind of sensor, for example 'optical', 'radar' or 'thermal'

satellite_images (primary key image_id)

ColumnTypeMeaning
image_idINTEGERImage identifier
image_nameVARCHAR(100)Image name
sensor_idINTEGERSensor that captured the image; references sensors.sensor_id
latitudeDECIMAL(9,6)Latitude of the image center in degrees; may be out of range or NULL
longitudeDECIMAL(9,6)Longitude of the image center in degrees; may be out of range or NULL
capture_timeTIMESTAMPWhen the image was captured
resolution_metersDECIMAL(8,2)Ground resolution in meters per pixel
cloud_cover_pctDECIMAL(5,2)Share of the image covered by cloud, in percent
file_size_mbDECIMAL(10,2)File size in megabytes

Output Contract

  • One row per image with valid coordinates, with these columns in this order: image_id, image_name, sensor_name, sensor_type, latitude, longitude, capture_time, resolution_meters, cloud_cover_pct, file_size_mb.
  • Order by capture_time descending, then image_id ascending. image_id is unique, so the order is fully determined.
  • Return values as stored, with no rounding or reformatting.

Constraints and Clarifications

  • sensors has at most 100 rows and satellite_images at most 10,000 rows.
  • Valid coordinates are latitude in [-90, 90] and longitude in [-180, 180], limits included. Stored values can fall outside these ranges or be NULL, and such images are excluded.
  • cloud_cover_pct is 0.00 to 100.00 and resolution_meters is positive.
  • Every sensor_id in satellite_images references a valid sensor.
  • capture_time is never NULL, and several images can share the same capture_time.

Expected Output

Tables

sensorssatellite_images
sensors
ColumnType
sensor_idINTEGER
sensor_nameVARCHAR(50)
sensor_typeVARCHAR(20)
satellite_images
ColumnType
image_idINTEGER
image_nameVARCHAR(100)
sensor_idINTEGER
latitudeDECIMAL(9,6)
longitudeDECIMAL(9,6)
capture_timeTIMESTAMP
resolution_metersDECIMAL(8,2)
cloud_cover_pctDECIMAL(5,2)
file_size_mbDECIMAL(10,2)

Comments (0)

No comments yet. Be the first to comment!

Submit your answer

Approved first answer today earns 30 XP
Bold⌘BItalic⌘IInline code⌘`Bullet listTab to nest (○ ■)Numbered listTab to nest (a. i.)QuoteCode block
Formatting help
Language
Run code to see results here.

Browse More Questions