我希望从一整天内获得过去几小时的地址数量。
我试过这个,但它没有用。
SELECT FROM_UnixTime((sensordata1.time + 7200), '%Y-%c-%d') "Datum",
COUNT(DISTINCT sensordata1.address) "Bezoekers"
FROM sensordata1
WHERE 1
GROUP BY 1
ORDER BY FROM_UnixTime((sensordata1.time + 7200), '%Y-%c-%d')
我想用它制作一个grafiek所以我可以看到每小时过去多少。我希望看到这一天,并希望从每小时知道已经过去了多少事情。 (地址来自wifi传感器。)
答案 0 :(得分:0)
您可以将小时放入from_unixtime:
SELECT FROM_UnixTime(sensordata1.time, '%Y-%c-%d %h') "Datum", COUNT(DISTINCT sensordata1.address) "Bezoekers"
FROM sensordata1
WHERE 1
GROUP BY 1
ORDER BY FROM_UnixTime((sensordata1.time + 7200), '%Y-%c-%d %h')
或者您可以尝试:
select date(x1.Datum) as "Datum", hour(x1.Datum) as d_hour, count(distinct x1.address) as "Bezoekers"
from
(
select from_unixtime(sensordata1.time) "Datum", sensordata1.address
from sensordata1
) x1
group by date(x1.Datum), hour(x1.Datum)