SQL-结果从工作日(时间)和周(无时间)开始

小丑本人

我正在尝试解决问题。我需要从一个工作周中获取结果(例如,指定工作时间为上午7:00至8:00 pm),并且需要包括周末的结果(没有指定时间)。但我不知道如何在工作日解决问题并包括结果

select  
c.PatientId
,g.PatientId
,c.StartDate
,g.TransferOrdinalNumber

from ClinicalEvent C
join PatientIncomming G on C.PatientId=G.PatientId

where

(DATEPART(dw, StartDate) in (1,2,3,4,5))
and (
(CAST(StartDate as Time) between '20:00' and '23:59')
or 
(CAST(StartDate as Time) between '00:01' and '07:00')
)


and StartDate between '2020.02.01' and '2020.2.28'
and EventTypeId = '5365f53c-583b-4b53-bf50-2ec7c002e53c'
and g.TransferOrdinalNumber=1
group by C.PatientId, G.PatientId, c.StartDate, g.TransferOrdinalNumber
order by C.PatientId, G.PatientId 
新人

您可以使用UNION ALL语句在非常基本的方法中会有所帮助。

select  
c.PatientId
,g.PatientId
,c.StartDate
,g.TransferOrdinalNumber

from ClinicalEvent C
join PatientIncomming G on C.PatientId=G.PatientId

where

(DATEPART(dw, StartDate) in (1,2,3,4,5))
and (
(CAST(StartDate as Time) between '20:00' and '23:59')
or 
(CAST(StartDate as Time) between '00:01' and '07:00')
)


and StartDate between '2020.02.01' and '2020.2.28'
and EventTypeId = '5365f53c-583b-4b53-bf50-2ec7c002e53c'
and g.TransferOrdinalNumber=1
group by C.PatientId, G.PatientId, c.StartDate, g.TransferOrdinalNumber
UNION ALL

select  
c.PatientId
,g.PatientId
,c.StartDate
,g.TransferOrdinalNumber

from ClinicalEvent C
join PatientIncomming G on C.PatientId=G.PatientId

where

(DATEPART(dw, StartDate) in (6,7))
--and (
--(CAST(StartDate as Time) between '20:00' and '23:59')
--or 
--(CAST(StartDate as Time) between '00:01' and '07:00')
--)


and StartDate between '2020.02.01' and '2020.2.28'
and EventTypeId = '5365f53c-583b-4b53-bf50-2ec7c002e53c'
and g.TransferOrdinalNumber=1
group by C.PatientId, G.PatientId, c.StartDate, g.TransferOrdinalNumber
    order by C.PatientId, G.PatientId 

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

sql通过打开和关闭时间范围来计算工作日的工作时间

来自分类Dev

基于SQL Server班次的工作日,周末,公共假日和一天中的时间

来自分类Dev

SQL查询基于时间戳选择按小时(col)和工作日(行)分组的值

来自分类Dev

将工作日分成在员工计划SQL中设置的时间段

来自分类Dev

将工作日分成在员工计划SQL中设置的时间段

来自分类Dev

工作日SQL查询

来自分类Dev

SQL工作日查询

来自分类Dev

SQL转换为工作日和hh:mm

来自分类Dev

熊猫周工作日开始和结束

来自分类Dev

计算给定开始日期和工作/午餐时间的截止日期PL / SQL

来自分类Dev

SQL多案例时间和多个结果

来自分类Dev

如何在SQL Server的一个工作日中将时间分为多个时间戳记的进出时间

来自分类Dev

SQL仅返回工作日

来自分类Dev

SQL触发日期范围与工作日

来自分类Dev

SQL日期差异工作日

来自分类Dev

SQL仅返回工作日

来自分类Dev

SQL日期差异工作日

来自分类Dev

SQL Server DATEADD特定的工作日

来自分类Dev

sql仅在工作日插入数据

来自分类Dev

工作日之间的周末 SQL

来自分类Dev

使用确切时间的 SQL 查询开始时间和结束时间

来自分类Dev

SQL 计算查询开始时间和持续时间以查找结束时间

来自分类Dev

获取事务的开始和结束时间-SQL Server

来自分类Dev

Oracle SQL查询中的开始/结束日期和时间

来自分类Dev

linq查询可将时间间隔分为每天的批处理,开始和结束部分为工作日

来自分类Dev

如何在PL / pgSQL中根据开始日期和持续时间(工作日)获取结束日期?

来自分类Dev

仅工作日在两个日期和两次之间进行SQL查询

来自分类Dev

SQL Server 在工作日的 07H00 和 23H00 期间计算

来自分类Dev

SQL中的日期时间到年+周

Related 相关文章

热门标签

归档