Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Average Without @avg

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Average Without @avg. Start with the requirements and the one table on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

If you did not have the AVG function, how would you find the average for cells A1-A10?

Assume the cells are stored as rows in PostgreSQL. Treat NULL cell values as blank cells that should be excluded from the calculation, and return NULL if every selected cell is blank.

Output

  1. Return one row with one column named average_value.
  2. Calculate the result only from cells A1 through A10.
  3. Return the average as a numeric value rounded to four decimal places.

Schema

spreadsheet_cells
ColumnTypeDescription
cell_idPKINTUnique identifier for the stored cell
cell_labelVARCHAR(10)Spreadsheet-style cell label
cell_valueNUMERIC(12,4)Numeric value stored in the cell, or NULL for a blank cell
Tablesspreadsheet_cells
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results