Saturday, 28 September 2013

MySql: read database table entry which is next to timestamp

MySql: read database table entry which is next to timestamp

I have a mysql database storing the energy produced by an inverter. The
values are stored summed up every x min in column "kWh_Dag". Now I would
like to read, what energy has been produced that day up to a specific time
of the day. The values are stored with the timestamp written "Datum_Dag".
I tried
SELECT `kWh_Dag` from `tgeg_dag` WHERE `Datum_dag` IN (SELECT
MAX(`Datum_Dag`) FROM `tgeg_dag` WHERE `Datum_Dag` < "2013-09-27
00:00:00")
but the database does not return anything. The "inline" SQL statement does
return the right timestamp belonging to the table entry which is the one I
want.
Is this the smartest way to access the wanted database entry?
Thanks

No comments:

Post a Comment