好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > SQLserver 實現分組統計查詢(按月、小時分組)

SQLserver 實現分組統計查詢(按月、小時分組)

熱門標簽:長沙智能外呼系統 電銷機器人公司 需要哪些牌照 知名電銷機器人價格 廣東防封卡外呼系統原理是什么 分享百度地圖標注多個位置 外呼系統改進 湖南電腦外呼系統平臺 地圖標注牌 菏澤語音電銷機器人加盟公司

設置AccessCount字段可以根據需求在特定的時間范圍內如果是相同IP訪問就在AccessCount上累加。

復制代碼 代碼如下:

Create table Counter
(
CounterID int identity(1,1) not null,
IP varchar(20),
AccessDateTime datetime,
AccessCount int
)

該表在這兒只是演示使用,所以只提供了最基本的字段
現在往表中插入幾條記錄
insert into Counter
select '127.0.0.1',getdate(),1 union all
select '127.0.0.2',getdate(),1 union all
select '127.0.0.3',getdate(),1

1 根據年來查詢,以月為時間單位
通常情況下一個簡單的分組就能搞定
復制代碼 代碼如下:

select
convert(varchar(7),AccessDateTime,120) as Date,
sum(AccessCount) as [Count]
from
Counter
group by
convert(varchar(7),AccessDateTime,120)

像這樣分組后沒有記錄的月份不會顯示,如下:

這當然不是我們想要的,所以得換一種思路來實現,如下:
復制代碼 代碼如下:

declare @Year int
set @Year=2009
select
m as [Date],
sum(
case when datepart(month,AccessDateTime)=m
then AccessCount else 0 end
) as [Count]
from
Counter c,
(
select 1 m
union all select 2
union all select 3
union all select 4
union all select 5
union all select 6
union all select 7
union all select 8
union all select 9
union all select 10
union all select 11
union all select 12
) aa
where
@Year=year(AccessDateTime)
group by
m

查詢結果如下:

2 根據天來查詢,以小時為單位。這個和上面的類似,代碼如下:
復制代碼 代碼如下:

declare @DateTime datetime
set @DateTime=getdate()
select
right(100+a,2)+ ':00 -> '+right(100+b,2)+ ':00 ' as DateSpan,
sum(
case when datepart(hour,AccessDateTime)> =a
and datepart(hour,AccessDateTime) b
then AccessCount else 0 end
) as [Count]
from Counter c ,
(select 0 a,1 b
union all select 1,2
union all select 2,3
union all select 3,4
union all select 4,5
union all select 5,6
union all select 6,7
union all select 7,8
union all select 8,9
union all select 9,10
union all select 10,11
union all select 11,12
union all select 12,13
union all select 13,14
union all select 14,15
union all select 15,16
union all select 16,17
union all select 17,18
union all select 18,19
union all select 19,20
union all select 20,21
union all select 21,22
union all select 22,23
union all select 23,24
) aa
where datediff(day,@DateTime,AccessDateTime)=0
group by right(100+a,2)+ ':00 -> '+right(100+b,2)+ ':00 '

查詢結果如下圖:

您可能感興趣的文章:
  • sql server遞歸子節點、父節點sql查詢表結構的實例
  • SQL Server 樹形表非循環遞歸查詢的實例詳解
  • 使用SqlServer CTE遞歸查詢處理樹、圖和層次結構
  • 使用SQLSERVER 2005/2008 遞歸CTE查詢樹型結構的方法
  • SQLSERVER2005 中樹形數據的遞歸查詢
  • SQLserver2008使用表達式遞歸查詢
  • 高效的SQLSERVER分頁查詢(推薦)
  • SQL Server SQL高級查詢語句小結
  • Sql server2005 優化查詢速度50個方法小結
  • sqlserver 模糊查詢常用方法
  • sql server實現遞歸查詢的方法示例

標簽:珠海 福建 天水 呼和浩特 商洛 西寧 美容院 泉州

巨人網絡通訊聲明:本文標題《SQLserver 實現分組統計查詢(按月、小時分組)》,本文關鍵詞  SQLserver,實現,分組,統計,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《SQLserver 實現分組統計查詢(按月、小時分組)》相關的同類信息!
  • 本頁收集關于SQLserver 實現分組統計查詢(按月、小時分組)的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 少妇被又大又粗又爽黄老大爷小| 老女人bbb| 国产盗摄xXxX视频video| 国产亚州精品视频| 大香焦伊在线| 午夜精品在线观看| gog0美女大尺度人体私拍| 穆桂英沦为军妓调教| 久久精品人人槡人妻| 性色AV无码成人亚洲一区| 我的年轻大胸继坶3在线观看| 男人扎爽进女人j羞羞漫画免费看| 91短视频在线高清hd| 性交姿势图片| 免费高清日本社区| 在线综合+亚洲+欧美中文字幕| 182成人免费精品区区区| 色老板在线看| www.中文字幕在线观看| 公交车伸进她的裤裙揉捏| 女朋友第一次感觉很松弛怎么办| 猛草视频| 国模私拍在线| 扶着粗大用力挺进嗯啊视频男男 | 日日噜噜噜夜夜爽爽狠狠福利| 日本aⅴ在线不卡免费观看| 女同穿带阳巨互慰小说| 午夜影院福利| 久久久久久精品亚洲大师码| 精品国产亚洲一区二区三区大结局| 哈啊~孕夫大肚高h双性| 中文无码热在线视频| 含桃车| 91福利国产在线观看菠萝蜜| 乱Japanese偷窥厨房| 男人用鸡鸡捅女人| 最新韩国伦理片大全手机在线播放| 成人永久免费视频网站在线观看| 欧美老女人的性生活| 免费国产精品视频| 久久久精品久久久666软件特点|