Verified rating by shop

joins

Verified rating by shop

Etsy SQL Interview Question

Etsy shows buyers a shop's rating based only on reviews from verified purchases.

For each shop with at least one verified review, return the shop_name, the number of verified reviews as verified_reviews, and their average rating as avg_rating, rounded to 2 decimal places. Sort by avg_rating, highest first, then by shop_name.

Asked of

  • Data Analyst
  • Business Analyst
  • BI Analyst
  • Product Analyst
  • Analytics Engineer

reviewsTable18 rows

Column NameType
review_idBIGINT
shop_idBIGINT
ratingBIGINT
review_dateDATE
verified_purchaseBOOLEAN
helpful_votesBIGINT

shopsTable10 rows

Column NameType
shop_idBIGINT
shop_nameVARCHAR
tagsVARCHAR
opened_yearBIGINT

reviewsExample Input

review_idshop_idratingreview_dateverified_purchasehelpful_votes
90001410152024-03-02true12
90002410242024-03-02true3
90003410152024-03-03false0
90004410352024-03-04true7
90005410432024-03-04true1
90006410252024-03-05true9
90007410522024-03-06false0
90008410342024-03-06true2
90009410452024-03-07false4
90010410552024-03-08true15
90011410112024-03-09true6
90012410652024-03-09true0
90013410252024-03-10false1
90014410642024-03-11true3
90015410352024-03-12true8
90016410452024-03-12true2
90017410542024-03-13false0
90018410652024-03-14true5

shopsExample Input

shop_idshop_nametagsopened_year
4101Oak and Threadhandmade|home decor2019
4102Rust Belt Findsvintage | home decor2016
4103Little Lantern Cohandmade|jewelry|gifts2021
4104Second Spin Recordsvintage2014
4105Clay Moon Studiohandmade | ceramics | home decor2020
4106Fern and Fablejewelry|gifts2022
4107Pressed Petalshandmade|gifts2018
4108Retro Rewindvintage|clothing2017
4109Knot Theoryhandmade | clothing2023
4110Silver Sparrowjewelry2015

Example Output

shop_nameverified_reviewsavg_rating
Clay Moon Studio15
Fern and Fable34.67
Little Lantern Co34.67
Rust Belt Finds24.5
Second Spin Records24
Oak and Thread23

Explanation

Oak and Thread has three reviews, but one is not from a verified purchase, so only its ratings of 5 and 1 count, for an average of 3. Fern and Fable and Little Lantern Co both average 4.67, so they are sorted by name.

The example above is a small slice of the data. Your query runs against the full tables.