[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
|