Myntra: Most Common Return Reasons in 2024

Easy
800.

Myntra: Most Common Return Reasons in 2024

The returns team is writing its annual review and wants to know which reasons shoppers picked most often when they sent something back or asked for an exchange.

Count the requests raised in calendar year 2024 (requested_on from 2024-01-01 to 2024-12-31), returns and exchanges together, per reason. Return reason and requests, ordered by requests descending, then by reason alphabetically. Reasons with no 2024 request do not appear.

A practice scenario set at Myntra: the tables and data are invented, and this is not a question from, or endorsed by, Myntra.

Tables

Table: ReturnRequest

ColumnTypeValues
return_idint
order_item_idint
reasonvarchar
request_typeenumreturn, exchange
requested_ondate

Primary key: return_id.

One row per return or exchange request. reason is the code the shopper picked, such as size_too_small or damaged.

Example

The rows must come back in the order shown.

ReturnRequest

return_idorder_item_idreasonrequest_typerequested_on
1501size_too_smallexchange2024-01-04
2502size_too_largereturn2024-02-11
3503size_too_smallreturn2024-03-20
4504damagedreturn2023-12-30
5505size_too_largeexchange2024-06-01
6506colour_differentreturn2024-12-31
7507changed_mindreturn2025-01-01
8508damagedreturn2024-07-15

Output

reasonrequests
size_too_large2
size_too_small2
colour_different1
damaged1
Read the hints, the editorial and the reference solution
-- Write your MySQL query below

Sign in to write, run and submit queries

A free account — no card, no trial clock. You come straight back here.

Run your query to see its result next to the expected one, example by example.

Myntra: Most Common Return Reasons in 2024 — SQL Problem

The returns team is writing its annual review and wants to know which reasons shoppers picked most often when they sent something back or asked for an…

  • Difficulty: Easy
  • Topics: Aggregation, Dates
  • Dialect: MySQL
  • Problem: #800

Problem statement

The returns team is writing its annual review and wants to know which reasons shoppers picked most often when they sent something back or asked for an exchange.

Count the requests raised in calendar year 2024 (requested_on from 2024-01-01 to 2024-12-31), returns and exchanges together, per reason. Return reason and requests, ordered by requests descending, then by reason alphabetically. Reasons with no 2024 request do not appear.

A practice scenario set at Myntra: the tables and data are invented, and this is not a question from, or endorsed by, Myntra.

Tables

Table: ReturnRequest

ColumnType
return_idint
order_item_idint
reasonvarchar
request_typeenum(return, exchange)
requested_ondate

Primary key: return_id.

One row per return or exchange request. reason is the code the shopper picked, such as size_too_small or damaged.

Examples

Example 1

ReturnRequest

return_idorder_item_idreasonrequest_typerequested_on
1501size_too_smallexchange2024-01-04
2502size_too_largereturn2024-02-11
3503size_too_smallreturn2024-03-20
4504damagedreturn2023-12-30
5505size_too_largeexchange2024-06-01
6506colour_differentreturn2024-12-31
7507changed_mindreturn2025-01-01
8508damagedreturn2024-07-15

Output

reasonrequests
size_too_large2
size_too_small2
colour_different1
damaged1

How to solve Myntra: Most Common Return Reasons in 2024

The question is a filter, a group and a sort. The WHERE clause keeps only requests raised in 2024; written as requested_on >= '2024-01-01' AND requested_on < '2025-01-01' it includes both New Year's Eve and New Year's Day of 2024 and leaves out the two neighbouring days, which the data puts there on purpose. YEAR(requested_on) = 2024 says the same thing and is the alternative, though it cannot use an index on the date.

GROUP BY reason then makes one group per reason that still has rows, and COUNT(*) counts them. A reason with no 2024 request has no rows left after the filter, so it forms no group and does not appear — exactly what the statement asks.

The order is fixed: most requests first, and when two reasons tie, alphabetical by reason. Without the second key the tied rows could come back in either order. The query reads the table once and sorts a handful of groups.

Reference solution (MySQL)

SELECT reason, COUNT(*) AS requests
FROM ReturnRequest
WHERE requested_on >= '2024-01-01' AND requested_on < '2025-01-01'
GROUP BY reason
ORDER BY requests DESC, reason ASC

Another way

SELECT reason, COUNT(return_id) AS requests FROM ReturnRequest WHERE YEAR(requested_on) = 2024 GROUP BY reason ORDER BY COUNT(return_id) DESC, reason

← Myntra: Live Styles With No Approved Catalogue Image · Myntra: Product Display Names From Brand, Colour and Article →