sql - MySQL ERROR 1241 (21000): Operand should contain 1 column(s) on Aggregate Query -
i using mysql ver 14.14 distrib 5.5.52, debian-linux-gnu (armv7l) using readline 6.3 running on raspbian os on raspberypi 3.
i run following query , following results.
mysql> select -> sensormeasurements.sensormeasurementdate, -> min(sensormeasurements.sensormeasurementvalue) "minvalue", -> max(sensormeasurements.sensormeasurementvalue) "maxvalue", -> avg(sensormeasurements.sensormeasurementvalue) "avgvalue" -> sensormeasurements -> inner join usersystemsensors -> on sensormeasurements.usersystemsensorid = -> usersystemsensors.usersystemsensorid -> inner join sensors -> on usersystemsensors.sensorid = sensors.sensorid -> inner join usersystems -> on usersystemsensors.usersystemid = usersystems.usersystemid -> inner join users -> on usersystems.userid = users.userid -> sensors.sensorid = 1 -> , sensormeasurements.sensormeasurementdatetime between -> "2016-11-05 10:00:00" , "2016-11-15 11:00:00" -> group (sensormeasurements.sensormeasurementdate); +-----------------------+----------+----------+-------------------+ | sensormeasurementdate | minvalue | maxvalue | avgvalue | +-----------------------+----------+----------+-------------------+ | 2016-11-05 | 66.9 | 73 | 69.56107784431138 | | 2016-11-06 | 51.5 | 73.4 | 64.03751600512162 | | 2016-11-07 | 40.3 | 68.7 | 58.34236111111102 | | 2016-11-08 | 39.2 | 59.4 | 48.1092361111111 | | 2016-11-09 | 13.2 | 54.8 | 36.78529850746269 | +-----------------------+----------+----------+-------------------+
when modify query following error error 1241 (21000): operand should contain 1 column(s)
select sensors.sensorname, sensormeasurements.sensormeasurementdate, min(sensormeasurements.sensormeasurementvalue) "minvalue", max(sensormeasurements.sensormeasurementvalue) "maxvalue", avg(sensormeasurements.sensormeasurementvalue) "avgvalue" sensormeasurements inner join usersystemsensors on sensormeasurements.usersystemsensorid = usersystemsensors.usersystemsensorid inner join sensors on usersystemsensors.sensorid = sensors.sensorid inner join usersystems on usersystemsensors.usersystemid = usersystems.usersystemid inner join users on usersystems.userid = users.userid sensors.sensorid = 1 , sensormeasurements.sensormeasurementdatetime between "2016-11-05 10:00:00" , "2016-11-15 11:00:00" group (sensors.sensorname, sensormeasurements.sensormeasurementdate);
any ideas overlooking?
thanks steve
mihai's answer worked:
remove
()
group by
Comments
Post a Comment