SELECT
COUNT(X.ACTIVITY_ID)
FROM
(SELECT
ACTIVITY_ID
FROM
mi_s_data.dbo.[MI_FACT_ACTIVITY]
WHERE
Date_Key BETWEEN (convert(int, convert(varchar(10), DatePart(yyyy,GetDate()), 112)) - 2)*10000 + 101
AND convert(int, convert(varchar(10), GetDate(), 112))
UNION
SELECT
ACTIVITY_ID
FROM
[MI_S_DATA].[DBO].[MOS_FACT_ACTIVITY_V1] MFA
WHERE
Date_Key BETWEEN (convert(int, convert(varchar(10), DatePart(yyyy,GetDate()), 112)) - 2)*10000 + 101
AND convert(int, convert(varchar(10), GetDate(), 112))
AND MFA.ACTIVITY_UID IS NULL) X --Count is 1763046
在运行个人计数时如下:
select count(*)
from
(SELECT ACTIVITY_ID
FROM mi_s_data.dbo.[MI_FACT_ACTIVITY]
WHERE Date_Key BETWEEN (convert(int, convert(varchar(10), DatePart(yyyy,GetDate()), 112)) - 2)*10000 + 101
AND convert(int, convert(varchar(10), GetDate(), 112))) a --5774079
select count(*)
from
(SELECT ACTIVITY_ID
FROM [MI_S_DATA].[DBO].[MOS_FACT_ACTIVITY_V1] MFA
WHERE Date_Key BETWEEN (convert(int, convert(varchar(10), DatePart(yyyy,GetDate()), 112)) - 2)*10000 + 101 AND convert(int, convert(varchar(10), GetDate(), 112))
AND MFA.ACTIVITY_UID IS NULL) a--0
答案 0 :(得分:1)
SELECT
COUNT(X.ACTIVITY_ID)
FROM
(SELECT
ACTIVITY_ID
FROM
mi_s_data.dbo.[MI_FACT_ACTIVITY]
WHERE
Date_Key BETWEEN (convert(int, convert(varchar(10), DatePart(yyyy,GetDate()), 112)) - 2)*10000 + 101
AND convert(int, convert(varchar(10), GetDate(), 112))
UNION ALL
SELECT
ACTIVITY_ID
FROM
[MI_S_DATA].[DBO].[MOS_FACT_ACTIVITY_V1] MFA
WHERE
Date_Key BETWEEN (convert(int, convert(varchar(10), DatePart(yyyy,GetDate()), 112)) - 2)*10000 + 101
AND convert(int, convert(varchar(10), GetDate(), 112))
AND MFA.ACTIVITY_UID IS NULL) X --Count is 1763046