我想爲用戶顯示多久之前添加此記錄。 (如「0天5小時6分鐘」),所以我需要採取總分鐘數。並做數學。我在c#中做了,但現在我需要用sql語法來做,有沒有簡單的方法來做到這一點?在sql視圖中嵌入查詢和子查詢(以小時和分鐘爲單位的差異時間)
UPDATE: 由於@Andomar答案在這裏我得到了它作爲一個單獨的查詢工作,現在我需要將其添加到呼叫表的大圖..
select case when days > 0 then CAST(Days as varchar(6)) + ' Days ' else +
case when hours > 1 and hours < 24 then cast(hours as varchar(6)) + ' hours'
when hours > 1 and hours < 24 then '1 hour'
else ''
end + ' ' +
case when minutes > 1 and minutes < 60 then cast(minutes as varchar(6)) + ' minutes'
when minutes = 1 then '1 min.'
else ''
end
end as TimeOpen
From (
select datediff(HH, dbo.Calls.CallDate, getdate()) as hours
, datediff(MI, dbo.Calls.CallDate,getdate()) % 60 as minutes
, datediff(D, dbo.Calls.CallDate, getdate()) as Days
from calls where Status <> 7 and Status <> 4
) as SubQuery
而你的DBMS是......? – 2011-06-15 21:57:41
微軟SQL Server 2008的 – Ezi 2011-06-15 21:58:23