Problem Β· Database

Get Average Thermostat Temperature 🐑

● EasyAlarmINTERNOA

Problem statement

The devices table contains temperature devices installed in rooms. Return the average thermostat temperature for each room that has more than two thermostat rows.

Round each average to the nearest whole number and return the rows in descending order by room_name.

Table schema

MySQLPostgreSQLPandas

Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.

devices

Temperature-related devices installed in rooms.

ColumnTypeNullableDescription
room_nameTextNoRoom containing the device.
device_typeTextNoDevice classification.
temperatureDecimalNoTemperature reported by the device.

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
room_nameTextNoβ€”
average_temperatureDecimalNoβ€”

Row order: must match exactly. Numeric tolerance: 0.

Constraints

  • Only rows whose device_type is exactly Thermostat count.
  • A room with exactly two thermostats is not included.
  • If an average is exactly halfway between two integers, round away from zero.
  • Return the columns as room_name and average_temperature.

More Alarm problems