Jump to content


Photo

Retrieving Specific Data


  • Please log in to reply
2 replies to this topic

#1 SimonSaysCode

SimonSaysCode

    Newbie

  • New Members
  • Pip
  • 3 posts

Posted 13 November 2012 - 12:46 PM

Hello All,
So I am attempting to get the previous day's data from my table, but I want it to be averaged by hour (I have an entry for every 5 minute interval).
So I assumed it would look something like this:
$sth = $db->prepare("SELECT AVG(Power) AS AvgPower,
strftime('%H', Timestamp, 'unixepoch', 'localtime') AS TheDate
FROM TestTable
WHERE datetime(Timestamp, 'unixepoch') >= datetime('now', '- 24 hours')
GROUP BY TheDate");
This isn't working however, so I was hoping someone could tell me where I am going wrong.
Thanks!

#2 SimonSaysCode

SimonSaysCode

    Newbie

  • New Members
  • Pip
  • 3 posts

Posted 13 November 2012 - 01:15 PM

Additionally, I should mention that I am using SQLite and PHP.

#3 SimonSaysCode

SimonSaysCode

    Newbie

  • New Members
  • Pip
  • 3 posts

Posted 14 November 2012 - 08:03 PM

Hello All,
So I am attempting to get the previous day's data from my table, but I want it to be averaged by hour (I have an entry for every 5 minute interval).
So I assumed it would look something like this:

$sth = $db->prepare("SELECT AVG(Power) AS AvgPower,
strftime('%H', Timestamp, 'unixepoch', 'localtime') AS TheDate
FROM TestTable
WHERE datetime(Timestamp, 'unixepoch') >= datetime('now', '-24 hours')
GROUP BY TheDate");
This isn't working however, so I was hoping someone could tell me where I am going wrong.
Thanks!

The space in between the - and 24 was the problem. Solved.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com