Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Weighted Search Ranking
00:00
5 left

Weighted Search Ranking

MediumSQL · PostgreSQL

Problem

How would you design a search algorithm that returns weighted search results?

Assume each candidate result has a text relevance score and a popularity score. Write a SQL query that returns active results for one search phrase, calculating a weighted score using 70% text relevance and 30% popularity. Treat a missing popularity score as zero.

Output

  1. One row per included search result with result_id, title, and weighted_score
  2. Include only active results for the search phrase hvac repair
  3. Sort by weighted_score descending, then result_id ascending for ties

Schema

search_results
ColumnTypeDescription
result_idPKINTUnique identifier for a search result
search_queryVARCHAR(100)Search phrase associated with the candidate result
titleVARCHAR(255)Title displayed for the result
result_typeVARCHAR(50)Type of searchable result
relevance_scoreDECIMAL(5,2)Text matching score from 0.00 to 1.00
popularity_scoreDECIMAL(5,2)Popularity score from 0.00 to 1.00
is_activeBOOLEANWhether the result is eligible for display
Tablessearch_results
Interviewer

Your question is Weighted Search Ranking. Start with the requirements and the one table in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.