select customerno,(GETDATE() - date_connected) as days_connected from (
select customerno, min(ch.connectiondatetime) as date_connected
from ConnectionHistory ch
GROUP by customerno
having (GETDATE() - date_connected > 90)
)
答案 0 :(得分:0)
我认为您需要DATEDIFF
函数和now()
,因为getdate()是sql server函数
select customerno,DATEDIFF( date(now()), date(date_connected)) as days_connected from
(
select ch.customerno, min(ch.connectiondatetime) as date_connected
from ConnectionHistory ch
GROUP by customerno
having DATEDIFF(date(now()),date(date_connected))>90
) as T