在 Teradata SQL 助手中使用 UNION 时缩短的字符串

Strings shortened when using UNION in Teradata SQL Assistant

当我在 2 个表之间执行 UNION 时,字符串会自动缩短。我得到“30 天活跃 Su”和“120 天活跃 S”。当我 运行 单独查询时,没有任何 UNION,我得到我需要的完整形式“30 天活跃订阅者”和“120 天活跃订阅者”。为什么会这样以及如何纠正它?

代码如下:

SELECT
'30 Days Active Subs' AS PROPERTY
,(DISTINCT SUBS.SUBSCRIBER_COUNT) AS SUBS_COUNT
FROM PMP_AVEW.FCT_SUBS_DLY_SNAP AS SUBS
WHERE SUBS.DAYS=30
GROUP BY 1

UNION

SELECT 
'120 Days Active Subs' AS PROPERTY
,(DISTINCT SUBS.SUBSCRIBER_COUNT) AS SUBS_COUNT
FROM PMP_AVEW.FCT_SUBS_DLY_SNAP AS SUBS
WHERE SUBS.DAYS=120

你需要投这个专栏。

SELECT
CAST('30 Days Active Subs' AS varchar(255)) AS PROPERTY
,(DISTINCT SUBS.SUBSCRIBER_COUNT) AS "30_DAYS_SUBS"
FROM PMP_AVEW.FCT_SUBS_DLY_SNAP AS SUBS
WHERE SUBS.DAYS=30
GROUP BY 1

UNION

SELECT 
'120 Days Active Subs' AS PROPERTY
,(DISTINCT SUBS.SUBSCRIBER_COUNT) AS "120_DAYS_SUBS"
FROM PMP_AVEW.FCT_SUBS_DLY_SNAP AS SUBS
WHERE SUBS.DAYS=120

或者您可以使用固定长度

 CAST('30 Days Active Subs' AS CHARACTER(20))