在 MSQuery 中使用字段别名不适用于 DB2

Using field alias in MSQuery does not work with DB2

此查询在 Data Studio 中有效,但在 MS Query 中无法显示别名! 我尝试了不同的类型,例如 "",'',[] 甚至 https://support.microsoft.com/en-us/kb/298955

SELECT 'TRANIN'AS NAME, SUM(CASE WHEN ALT3.TRANINDT BETWEEN 20150603 AND 20150601 THEN 1 else 0 END) AS CurrentMonth, SUM(CASE WHEN ALT3.TRANINDT BETWEEN 20150501 AND 20150531 THEN 1 else 0 END) AS LastMonth 从 ALT3

MS 很久以前就中断了 MS 查询...

我试图让它正常工作,但没有任何效果。我几乎放弃了。

通常我只是在数据返回 Excel 后重命名该列。

但是如果你真的想要从 MS 查询返回的名字,这行得通:

WITH tbl AS (SELECT 'TRANIN'AS NAME
             , SUM(CASE WHEN ALT3.TRANINDT BETWEEN 20150603 AND 20150601 
                     THEN 1 else 0 END) AS CurrentMonth
             , SUM(CASE WHEN ALT3.TRANINDT BETWEEN 20150501 AND 20150531 
                     THEN 1 else 0 END) AS LastMonth 
             FROM ALT3)
SELECT * FROM TBL