如何显示上个月每小时放置的订单? [英] How to display orders that were placed per hour of the day for last month?

查看:70
本文介绍了如何显示上个月每小时放置的订单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示上个月每小时每小时放置的所有不同订单。请帮忙!谢谢

I need to display all the distinct orders that were placed per hour of the day for the last month. Please Help! Thanks

SELECT a.PatientAccountID
,b.OrderSubTypeAbbr
,b.CreationTime
 
FROM PatientVisit a with( nolock) 
INNER JOIN Order b with( nolock) 
ON a.PatientVisit_oid=b.PatientVisit_oid
WHERE a. VisitTypeCode ='IP'

AND b.OrderSubTypeAbbr IN ('CT Scan','MRI')
AND b.CreationTime >=DATEADD(m,-1,GETDATE())
ORDER BY a.PatientAccountID

推荐答案

WHERE a. VisitTypeCode ='IP'

AND b.OrderSubTypeAbbr IN ('CT Scan','MRI')

-- to filter by month
AND month(b.CreationTime) >= @month -- ' get month from design  'parameter''

-- to filter by hour
and DATEPART(hour,b.CreationTime) = @hour -- get it from design 'parameter'

ORDER BY a.PatientAccountID


这篇关于如何显示上个月每小时放置的订单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆