sql

Median order value per segment

SQL & Data Modeling · Aggregation · medium · Original Uplift question · PostgreSQL · 8 min

Return the median order amount for each customer segment. Do not assume a MEDIAN() function exists.

Fixture

orders

segment, amount

create table orders (segment text, amount numeric);
insert into orders values
 ('new',10),('new',20),('new',30),('new',100),
 ('returning',50),('returning',60);

Evaluation criteria

  • Groups by segment
  • Does not rely on a nonexistent MEDIAN() function
  • One row per segment

Detailed grading feedback appears after you submit.

Source

Original Uplift question based on a common interview pattern.

Your answer

You get one graded attempt here without an account. Create a free account for unlimited attempts, saved progress and community write-ups.

Answers stay hidden until you ask. Reveal the full model write-up when you are ready to compare.

Community

How other people solved this

There is rarely one right query or one right framing. Read how others approached it, and share your own once you have submitted an answer.

Reading is open to everyone. Sign in to share your approach or mark a write-up as helpful.

Loading write-ups…