我有一个像
这样的Select语句select AVG(CAST(DATEDIFF(Day,CreatedDate,FirstTouchDate) AS BIGINT) else null end) AS avgdaystofirstattempt,
AVG(CAST(DATEDIFF(Day,CreatedDate,Completeddate) AS BIGINT)) AS AvgDaystoComplete
from Table1
如何为列avgdaystofirstattempt编写条件 - FirstTouchdate不喜欢'%1900%'在选择本身但不在where子句中。
提前致谢
答案 0 :(得分:0)
您可以使用CASE
选择性地在汇总语句中包含数据。你的问题并不是很清楚,但我认为你想要这样的事情:
SELECT AVG(
CASE
WHEN DATEDIFF(Day,CreatedDate,FirstTouchDate) < 1900 THEN NULL
ELSE CAST(DATEDIFF(Day,CreatedDate,FirstTouchDate) AS BIGINT)
END
) AS avgdaystofirstattempt,
AVG(CAST(DATEDIFF(Day,CreatedDate,Completeddate) AS BIGINT)) AS AvgDaystoComplete
FROM Table1