将Tableau计算转换为SQL查询

时间:2019-02-02 03:28:09

标签: sql-server tsql tableau

我正在尝试通过编写SQL查询来验证Tableau值,但我不认为我完全理解了计算

计算为

IF      {   FIXED   Account ,  MonthYear :   MAX([type])   } = 'Upgrade' THEN    'Upgrade'
ELSE    {   FIXED   Account ,  MonthYear  :   MAX(plan)   }
END

SQL查询是

SELECT 
    ACCOUNT, 
    CASE 
       WHEN MAX(type) = 'Upgrade' 
          THEN 'Upgrade'
          ELSE MAX(plan) 
    END AS plan,
    MonthYear,
    USAGE
FROM  
    table
GROUP BY 
    Account, monthyear

数字与数据不一致,所以我只想确保我完全了解此Tableau计算正在做什么

1 个答案:

答案 0 :(得分:1)

查询不太有意义。你打算这样做吗?

SELECT ACCOUNT, 
       (CASE WHEN MAX(type) = 'Upgrade' then 'Upgrade'
             ELSE MAX(plan)
        END) as plan,
       MonthYear
FROM table
Group by Account, MonthYear