Prepin
Log in

[Considering a dataset that contains information about a food delivery service] Construct a SQL query to calculate the total number of rides and deliveries completed for each zip code.

Approach / Explanation

The question requires you to create an SQL query that determines the total number of rides and deliveries for each zip code. This task suggests that the dataset includes the relevant fields—likely two fields for the counts of rides and deliveries, as well as one for the zip code. To effectively address this question, consider the following key points: Be familiar with the specific column names and their corresponding data types within your dataset. It is essential to utilize the SQL GROUP BY clause to aggregate the total counts of rides and deliveries by zip code. You are expected to apply the SQL SUM function to compute the total rides and deliveries for each zip code.

Suggested Answer

Consider a dataset that includes two fields: rides and deliveries , stored in a table called food_delivery_service . Additionally, there is a field named zip_code that represents the zip code. Your SQL query would be structured as follows: SELECT zip_code , SUM ( rides ) AS total_rides , SUM ( deliveries ) AS total_deliveries FROM food_delivery_service GROUP BY zip_code ; This SQL query will yield a list of distinct zip codes along with the total counts of rides and deliveries made in each respective zip code.

Alternative Answer

In a different scenario, let's consider a table named transactions that contains comprehensive details about rides and deliveries, with individual rows for each type of transaction. This table includes the fields zip_code , transaction_type (which can be either ride or delivery), and completed_transactions . SELECT zip_code , SUM ( CASE WHEN transaction_type = 'ride' THEN completed_transactions END ) AS total_rides , SUM ( CASE WHEN transaction_type = 'delivery' THEN completed_transactions END ) AS total_deliveries FROM transactions GROUP BY zip_code ; This SQL query performs the following tasks: It calculates the sum of 'completed_transactions' where 'transaction_type' is 'ride', and labels this sum as 'total_rides'. It calculates the sum of 'completed_transactions' where 'transaction_type' is 'delivery', and labels this sum as 'total_deliveries'. These calculations will be done for each distinct 'zip_code', providing the total number of rides and deliveries completed within each zip code.

Question Details

Difficulty & Category

Medium
technical

Companies

Instacart

Product

For CandidatesFor RecruitersCompaniesBrowse JobsInterview QuestionsDeep ProfileSkill AssessmentOpportunity Matching
Prepin.ai

© 2026 Prepin LLC · Philadelphia, PA · All rights reserved.