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 Total Orders by Client Type
00:00
5 left

SQL Total Orders by Client Type

MediumSQL · PostgreSQL

Problem

PenFed Credit Union's marketing analytics team needs to compare order activity from new and existing clients during January 2025. A client is new if January contains their first recorded order, and existing if they placed an order before January 2025.

Write a PostgreSQL query that calculates the total number of January 2025 orders for each client type.

Requirements

  1. Determine each client's first recorded order date.
  2. Include only orders from 2025-01-01 through 2025-01-31, using an exclusive upper date boundary.
  3. Classify each included order as new or existing with CASE and return both categories, including a zero count if a category has no orders.
  4. Return client_type and total_orders, ordered with new before existing.

Schema

clients
ColumnTypeDescription
client_idPKINTUnique PenFed client identifier
client_nameVARCHAR(100)Client's display name
orders
ColumnTypeDescription
order_idPKINTUnique order identifier
client_idINTReferences clients.client_id
order_dateDATEDate the order was placed
Tablesclientsorders
Interviewer

Your question is SQL Total Orders by Client Type. 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.