0
我是tsql的新手,並使用mysql db。看一個示例代碼(在下面),從數據庫中獲取的數據,每2學時】每15分鐘獲取一次avg數據
SELECT date(`dateTime`) dateDay, 2*floor(date_format(`dateTime`,'%H')/2) dateHour,
avg(channel1), avg(channel2), avg(channel3)
FROM `Table`
WHERE `id` =1
AND `dateTime` >= '2011-10-15 00:00:01'
AND `dateTime` <= '2011-10-17 23:59:59'
然後我做了基於上面的代碼來獲得數據每15分鐘幾點變化:
SELECT date(`dateTime`) dateDay, 15*floor(date_format(`dateTime`,'%i')/15) dateHour,
avg(channel1), avg(channel2), avg(channel3)
FROM `Table`
WHERE `id` =1
AND `dateTime` >= '2011-10-15 00:00:01'
AND `dateTime` <= '2011-10-17 23:59:59'
group by date(`dateTime`), 15*floor(date_format(`dateTime`,'%i')/15)
然而,查詢不正確。
我的問題是:
- 如何修改查詢來獲取數據每15分鐘?
- 如何編寫sql查詢以獲取所有數據? dateDay和dateHour列需要在這裏。
[Group mysql query by 15 min intervals]可能重複(http://stackoverflow.com/questions/2793994/group-mysql-query-by-15-min-intervals) –