SELECT
(CASE WHEN (TIMESTAMP(DATE(TIMESTAMP([subscription_month]))) = TIMESTAMP(DATE(TIMESTAMP([month])))) THEN '2.New Members' WHEN ((TIMESTAMP(DATE(TIMESTAMP([subscription_month]))) < TIMESTAMP(DATE(TIMESTAMP([month]))))
AND (TIMESTAMP(DATE(TIMESTAMP([previous_month]))) IS NULL)) THEN '3.Reactivated Visitors' WHEN ((TIMESTAMP(DATE(TIMESTAMP([subscription_month]))) IS NULL)
AND (TIMESTAMP(DATE(TIMESTAMP([previous_month]))) IS NULL)) THEN '3.Reactivated Visitors' WHEN (CASE WHEN TIMESTAMP(DATE(TIMESTAMP([previous_month]))) IS NULL
OR TIMESTAMP(DATE(TIMESTAMP([month]))) IS NULL THEN INTEGER(NULL) ELSE INTEGER(( (12 * YEAR(TIMESTAMP(DATE(TIMESTAMP([month]))))) + MONTH(TIMESTAMP(DATE(TIMESTAMP([month])))) ) -( (12 * YEAR(TIMESTAMP(DATE(TIMESTAMP([previous_month]))))) + MONTH(TIMESTAMP(DATE(TIMESTAMP([previous_month])))) )) END = 1) THEN '1.Repeated Visitors' WHEN (CASE WHEN TIMESTAMP(DATE(TIMESTAMP([previous_month]))) IS NULL
OR TIMESTAMP(DATE(TIMESTAMP([month]))) IS NULL THEN INTEGER(NULL) ELSE INTEGER(( (12 * YEAR(TIMESTAMP(DATE(TIMESTAMP([month]))))) + MONTH(TIMESTAMP(DATE(TIMESTAMP([month])))) ) -( (12 * YEAR(TIMESTAMP(DATE(TIMESTAMP([previous_month]))))) + MONTH(TIMESTAMP(DATE(TIMESTAMP([previous_month])))) )) END > 1) THEN '3.Reactivated Visitors' ELSE 'Error' END) AS [Calculation_1030479950946398210],
COUNT((CASE WHEN (((CASE WHEN (TIMESTAMP(DATE(TIMESTAMP([subscription_month]))) = TIMESTAMP(DATE(TIMESTAMP(DATE(TIMESTAMP([month])))))) THEN '2.New Members' WHEN ((TIMESTAMP(DATE(TIMESTAMP([subscription_month]))) < TIMESTAMP(DATE(TIMESTAMP(DATE(TIMESTAMP([month]))))))
AND (TIMESTAMP(DATE(TIMESTAMP([previous_month]))) IS NULL)) THEN '3.Reactivated Visitors' WHEN ((TIMESTAMP(DATE(TIMESTAMP([subscription_month]))) IS NULL)
AND (TIMESTAMP(DATE(TIMESTAMP([previous_month]))) IS NULL)) THEN '3.Reactivated Visitors' WHEN (CASE WHEN TIMESTAMP(DATE(TIMESTAMP([previous_month]))) IS NULL
OR TIMESTAMP(DATE(TIMESTAMP(DATE(TIMESTAMP([month]))))) IS NULL THEN INTEGER(NULL) ELSE INTEGER(( (12 * YEAR(TIMESTAMP(DATE(TIMESTAMP(DATE(TIMESTAMP([month]))))))) + MONTH(TIMESTAMP(DATE(TIMESTAMP(DATE(TIMESTAMP([month])))))) ) -( (12 * YEAR(TIMESTAMP(DATE(TIMESTAMP([previous_month]))))) + MONTH(TIMESTAMP(DATE(TIMESTAMP([previous_month])))) )) END = 1) THEN '1.Repeated Visitors' WHEN (CASE WHEN TIMESTAMP(DATE(TIMESTAMP([previous_month]))) IS NULL
OR TIMESTAMP(DATE(TIMESTAMP(DATE(TIMESTAMP([month]))))) IS NULL THEN INTEGER(NULL) ELSE INTEGER(( (12 * YEAR(TIMESTAMP(DATE(TIMESTAMP(DATE(TIMESTAMP([month]))))))) + MONTH(TIMESTAMP(DATE(TIMESTAMP(DATE(TIMESTAMP([month])))))) ) -( (12 * YEAR(TIMESTAMP(DATE(TIMESTAMP([previous_month]))))) + MONTH(TIMESTAMP(DATE(TIMESTAMP([previous_month])))) )) END > 1) THEN '3.Reactivated Visitors' ELSE 'Error' END) = '3.Reactivated Visitors')
OR ((CASE WHEN (TIMESTAMP(DATE(TIMESTAMP([subscription_month]))) = TIMESTAMP(DATE(TIMESTAMP(DATE(TIMESTAMP([month])))))) THEN '2.New Members' WHEN ((TIMESTAMP(DATE(TIMESTAMP([subscription_month]))) < TIMESTAMP(DATE(TIMESTAMP(DATE(TIMESTAMP([month]))))))
AND (TIMESTAMP(DATE(TIMESTAMP([previous_month]))) IS NULL)) THEN '3.Reactivated Visitors' WHEN ((TIMESTAMP(DATE(TIMESTAMP([subscription_month]))) IS NULL)
AND (TIMESTAMP(DATE(TIMESTAMP([previous_month]))) IS NULL)) THEN '3.Reactivated Visitors' WHEN (CASE WHEN TIMESTAMP(DATE(TIMESTAMP([previous_month]))) IS NULL
OR TIMESTAMP(DATE(TIMESTAMP(DATE(TIMESTAMP([month]))))) IS NULL THEN INTEGER(NULL) ELSE INTEGER(( (12 * YEAR(TIMESTAMP(DATE(TIMESTAMP(DATE(TIMESTAMP([month]))))))) + MONTH(TIMESTAMP(DATE(TIMESTAMP(DATE(TIMESTAMP([month])))))) ) -( (12 * YEAR(TIMESTAMP(DATE(TIMESTAMP([previous_month]))))) + MONTH(TIMESTAMP(DATE(TIMESTAMP([previous_month])))) )) END = 1) THEN '1.Repeated Visitors' WHEN (CASE WHEN TIMESTAMP(DATE(TIMESTAMP([previous_month]))) IS NULL
OR TIMESTAMP(DATE(TIMESTAMP(DATE(TIMESTAMP([month]))))) IS NULL THEN INTEGER(NULL) ELSE INTEGER(( (12 * YEAR(TIMESTAMP(DATE(TIMESTAMP(DATE(TIMESTAMP([month]))))))) + MONTH(TIMESTAMP(DATE(TIMESTAMP(DATE(TIMESTAMP([month])))))) ) -( (12 * YEAR(TIMESTAMP(DATE(TIMESTAMP([previous_month]))))) + MONTH(TIMESTAMP(DATE(TIMESTAMP([previous_month])))) )) END > 1) THEN '3.Reactivated Visitors' ELSE 'Error' END) = '2.New Members')) THEN [user_id] ELSE NULL END)) AS [TEMP_Calculation_1133499793803542545__4248242405__0_],
COUNT([user_id]) AS [TEMP_Calculation_1133499793848455199__2157635628__0_],
MONTH(TIMESTAMP(DATE(TIMESTAMP([month])))) AS [mn_month_ok],
QUARTER(TIMESTAMP(DATE(TIMESTAMP([month])))) AS [qr_month_ok],
YEAR(TIMESTAMP(DATE(TIMESTAMP([month])))) AS [yr_month_ok]
FROM
[vex-custom:samyUS.visitors_analysis] [visitors_analysis]
WHERE
((TIMESTAMP(DATE(TIMESTAMP([month]))) >= TIMESTAMP('2011-01-01 00:00:00'))
AND (TIMESTAMP(DATE(TIMESTAMP([month]))) <= TIMESTAMP('2016-09-01 00:00:00')))
GROUP BY
1,
4,
5,
6