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
SQL Query for Expiring Groceries
00:00
5 left

SQL Query for Expiring Groceries

MediumSQL · PostgreSQL

Problem

HashedIn's QuickTrace inventory surface needs a daily view of groceries that are still available and will expire during the remainder of the current calendar week. Write a PostgreSQL query using the tables below.

Requirements

  1. Return groceries whose expiry date is from today through the end of the current week, excluding already expired items.
  2. Include groceries with no matching store record, showing a NULL store name.
  3. Return the grocery name, category, quantity, expiry date, store name, and an expiry_status of Expires today or Upcoming.
  4. Order by expiry date ascending, then grocery name ascending.

Schema

quicktrace_groceries
ColumnTypeDescription
grocery_idPKINTUnique grocery inventory record identifier
grocery_nameVARCHAR(100)Name of the grocery product
categoryVARCHAR(50)Grocery category
quantityINTAvailable inventory quantity
expiry_dateDATEDate on which the grocery expires
store_idINTAssociated QuickTrace store identifier
quicktrace_stores
ColumnTypeDescription
store_idPKINTUnique store identifier
store_nameVARCHAR(100)QuickTrace store name
cityVARCHAR(60)City where the store operates
Tablesquicktrace_groceriesquicktrace_stores
Interviewer

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