Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Word Frequency SQL Query

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

Your question is Word Frequency SQL Query. Start with the requirements and the two tables 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

Intuit's TurboTax content pipeline stores uploaded text files as individual tokens for quality checks. Write a PostgreSQL query that reports how many times each word appears in turbotax-help.txt.

Requirements

  1. Join the file metadata to its token rows using document_id.
  2. Normalize each token by converting it to lowercase and removing punctuation.
  3. Ignore NULL tokens and tokens that become empty after normalization.
  4. Return each normalized word and its occurrence count, ordered by count descending and then word ascending.

Schema

documents
ColumnTypeDescription
document_idPKINTUnique file identifier
file_nameVARCHAR(255)Uploaded file name
product_nameVARCHAR(100)Intuit product associated with the file
uploaded_atDATEDate the file was uploaded
word_tokens
ColumnTypeDescription
token_idPKINTUnique token identifier
document_idINTReferences documents.document_id
token_positionINTToken position within the document
tokenVARCHAR(255)Raw extracted token
Tablesdocumentsword_tokens
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results