Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 feedbackSuccess 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 Coding Question Count
00:00
5 left

SQL Coding Question Count

MediumSQL · PostgreSQL

Problem

Bosch Building Technologies uses binary sensor readings from building automation systems to monitor equipment states. Write a PostgreSQL query that counts how often readings with values 0 and 1 occur for each building with at least one active device.

Requirements

  1. Join active devices to their sensor readings.
  2. Count readings equal to 0 and readings equal to 1 separately for each building.
  3. Include active buildings whose devices have no readings, returning zero counts where appropriate.
  4. Ignore NULL readings and values other than 0 or 1, and sort the results alphabetically by building name.

Schema

devices
ColumnTypeDescription
device_idPKINTEGERUnique device identifier
device_nameVARCHAR(100)Bosch Building Technologies device name
building_nameVARCHAR(100)Building where the device is installed
sensor_typeVARCHAR(50)Type of monitored sensor
is_activeBOOLEANWhether the device is currently active
sensor_readings
ColumnTypeDescription
reading_idPKINTEGERUnique reading identifier
device_idINTEGERDevice that produced the reading
reading_valueSMALLINTBinary or other recorded sensor value
Tablesdevicessensor_readings
Interviewer

Your question is SQL Coding Question Count. 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.