The UK Home Automation Archive

Archive Home
Group Home
Search Archive


Advanced Search

The UKHA-ARCHIVE IS CEASING OPERATIONS 31 DEC 2024


[Message Prev][Message Next][Thread Prev][Thread Next][Message Index][Thread Index]

Re: [OT] Sql help, for electronic meter reading




Paul Smith wrote:
> Hi Guys,

[Topic marked OT]

> SELECT Sum(reading) AS Reading FROM `electric` where Date between
> '2005-03-29 12:00:00' and '2005-03-29 13:00:00'

This returns the sum as you stated...but you go onto say..

> What I want
> to get is a complete list for the last 24 hrs. so I think I need to
> create 24 sql statements. But was wondering if there was a better way.

You dont mention which version of SQL you are using (MSSQL, PostGres,
MySQL etx) however most SQL implementations you can use the NOW()
function to return the current date, and DATEDIFF() to work out
differences between dates.

If you change the SUM(reading) to be just *, you'll get back a list
instead of summation, which appears to be what you require.

Cheers,

/Neil/



UKHA_D Main Index | UKHA_D Thread Index | UKHA_D Home | Archives Home

Comments to the Webmaster are always welcomed, please use this contact form . Note that as this site is a mailing list archive, the Webmaster has no control over the contents of the messages. Comments about message content should be directed to the relevant mailing list.