Referring to a Column Alias in a WHERE Clause

后端 未结 9 2037
你的背包
你的背包 2020-11-22 05:38
SELECT logcount, logUserID, maxlogtm
   , DATEDIFF(day, maxlogtm, GETDATE()) AS daysdiff
FROM statslogsummary
WHERE daysdiff > 120

I get

9条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 06:18

    Came here looking something similar to that, but with a CASE WHEN, and ended using the where like this: WHERE (CASE WHEN COLUMN1=COLUMN2 THEN '1' ELSE '0' END) = 0 maybe you could use DATEDIFF in the WHERE directly. Something like:

    SELECT logcount, logUserID, maxlogtm
    FROM statslogsummary
    WHERE (DATEDIFF(day, maxlogtm, GETDATE())) > 120
    

提交回复
热议问题