SQL按日、周、月、年统计

古城微笑少年丶 2022-08-24 00:56 376阅读 0赞

1、按日统计:

  1. select convert(varchar(13),RingTime,120) as RingTime,count(*) as DialCount
  2. from D_CallRecords (nolock) group by convert(varchar(13),RingTime,120)

2、按周统计:

  1. select datename(dw,dateadd(dd,-1,D_CallRecords.RingTime)) as RingTime from D_CallRecords
  2. group by datename(dw,dateadd(dd,-1,D_CallRecords.RingTime))

3、按月统计:

  1. select day([RingTime]) as RingTime from D_CallRecords (nolock) where year([RingTime]) =2014 and month([RingTime]) =6 group by day([RingTime])

4、按年统计:

  1. select month([RingTime]) as Months from D_CallRecords (nolock) where year([RingTime]) =2014 group by month([RingTime])

发表评论

表情:
评论列表 (有 0 条评论,376人围观)

还没有评论,来说两句吧...

相关阅读