I have the following MySQL Select Statement in some PHP that works great:
Here is the full dataset: https://www.dropbox.com/s/65dwada48xh45f1/MySQL_HomeSeerDB.sql?dl=1
SELECT CONCAT(LEFT(DATE(EntryDateTime),10),' ',HOUR(EntryDateTime),':00:00') as DateHour, SUM(HSConnectDown) as HSDownCount FROM State GROUP BY DATE(EntryDateTime),HOUR(EntryDateTime)
I want to limit the results to only those where "DateHour" is the same as today's date. I have the code for that using the following:
WHERE DATE('DateHour') = DATE(CONVERT_TZ(CURRENT_TIMESTAMP,'+00:00','-6:00'))
I just do not know how to put together a MySQL Select statement that will filter the results.
Here is an example output with no where field:
DateHour HSDownCount
------------------- ------------
2018-03-02 13:00:00 1
2018-03-02 14:00:00 0
2018-03-02 15:00:00 0
2018-03-02 16:00:00 0
2018-03-02 17:00:00 1
2018-03-02 18:00:00 0
2018-03-02 19:00:00 2
2018-03-02 20:00:00 0
2018-03-02 21:00:00 1
2018-03-02 22:00:00 0
2018-03-02 23:00:00 0
2018-03-03 0:00:00 0
2018-03-03 1:00:00 1
2018-03-03 2:00:00 0
2018-03-03 3:00:00 0
2018-03-03 4:00:00 0
2018-03-03 5:00:00 0
2018-03-03 6:00:00 0
2018-03-03 7:00:00 0
2018-03-03 8:00:00 0
2018-03-03 9:00:00 0
2018-03-03 10:00:00 1
2018-03-03 11:00:00 1
2018-03-03 12:00:00 0
2018-03-03 13:00:00 0
2018-03-03 14:00:00 0
2018-03-03 15:00:00 1
2018-03-03 16:00:00 0
When I use any kind of WHERE clause for DateHour I get an error... Example:
SELECT CONCAT(LEFT(DATE(EntryDateTime),10),' ',HOUR(EntryDateTime),':00:00') as DateHour, SUM(HSConnectDown) as HSDownCount
FROM State
WHERE DateHour = '2018-03-03 11:00:00'
GROUP
BY DATE(EntryDateTime),HOUR(EntryDateTime)
MySQL said:
#1054 - Unknown column 'DateHour' in 'where clause'
Can anyone help me with this?