SQL错误[102] [42000]:“)”附近的语法不正确

时间:2018-07-23 10:04:41

标签: mysql

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)
)

1 个答案:

答案 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

http://www.sqlfiddle.com/#!9/92ff29e/2