我正在尝试获取总停留时间,即AdmitDate和DischargeDate在用户提供的时间段内的总日期差异(AdmitDate为FromDate,DischargeDate为ToDate) 然后应用以下公式
和期间的天数将是AdmitDate作为FromDate和DischargeDate作为ToDate ,我无法找到一种方法来编写查询而不会得到任何错误的
答案 0 :(得分:1)
SELECT *,DATEDIFF(hour, AdmitDate, DischargeDate) AS 'Total Length of stay',
DATEDIFF(day, AdmitDate, DischargeDate) AS 'Number of Days in the period',
(DATEDIFF(hour, AdmitDate, DischargeDate)*100)/(133*DATEDIFF(day, AdmitDate, DischargeDate))
AS Formula
from TableName
DATEDIFF()
函数根据指定的时间间隔返回两个日期值之间的差异。
语法: DATEDIFF(Interval, date1, date2)
答案 1 :(得分:0)
SELECT(DATEDIFF(分钟,AdmitDate,DischargeDate))/ 133 *(DATEDIFF(day,AdmitDate,DischargeDate)* 100)