比如我要統計每天晚上8:00到晚上12:00的訪問量,重點其實就是日期之間的格式轉換和拼接,即to_date和to_char的靈活應用
select to_char(t.accesstime, 'yyyy/mm/dd') 訪問量,
to_char(t.accesstime, 'yyyy/mm/dd') 時間
from table_name t
where t.accesstime between
to_date(to_char(t.accesstime, 'yyyy/mm/dd') || ' 20:00:00',
'yyyy-mm-dd hh24:mi:ss') and
to_date(to_char(t.accesstime, 'yyyy/mm/dd') || ' 23:59:59',
'yyyy-mm-dd hh24:mi:ss')
group by to_char(t.accesstime, 'yyyy/mm/dd')
order by to_char(t.accesstime, 'yyyy/mm/dd') desc
結果如下
mysql按照時間段內 每天統計
sql select t.report time,count report time from select date format report time,y m d as report time from report count as t group by t.report time date...
查詢指定時間段的資料
一 select from searchdetails where searchdatetime between 2014 10 06 01 40 50.123 and 2014 12 07 23 12 and datepart hour,searchdatetime between 1 and 1...
Oracle 按時間段分組統計
想要按時間段分組查詢,首先要了解level,connect by,oracle時間的加減.關於level這裡不多說,我只寫出乙個查詢語句 sql view plain copy level 是乙個偽例 select level from dual connect bylevel 10 結果 1 2 ...