码迷,mamicode.com
首页 > 数据库 > 详细

数据库--查询--按小时查询&在where里面使用sum函数

时间:2017-12-11 16:13:03      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:ant   order   sum函数   时间   sel   order by   pos   ndt   div   

查询:将数据库-表中-若干日期-按一天24小时,将所有日期同一时间的数据求和。

学习点:将数据按小时分组求和

1 declare @BgainTime varchar(50)=2017-11-01  
2 declare @EndTime varchar(50)  =2017-12-01
3 --每小时发药处方量
4 select 时间=datepart(hh,ReceiveTime),发药量=count(*) from Prescription 
5 where ReceiveTime between  @BgainTime and @EndTime
6 group by datepart(hh,ReceiveTime)
7 order by datepart(hh,ReceiveTime)

如果想在where条件使用sum函数,通过having来实现:

select  PrescCode from PrescriptionDetail group by PrescCode having sum(OutQuantity)>=sum(Quantity)

 

数据库--查询--按小时查询&在where里面使用sum函数

标签:ant   order   sum函数   时间   sel   order by   pos   ndt   div   

原文地址:http://www.cnblogs.com/EasonDongH/p/8023240.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!