【问题标题】:How to fix "[Teradata][ODBC Teradata Driver][Teradata Database] Syntax error: ORDER BY is not allowed in subqueries." in tableau query如何修复“[Teradata][ODBC Teradata Driver][Teradata Database] 语法错误:子查询中不允许使用 ORDER BY。”在表格查询中
【发布时间】:2019-09-22 21:42:07
【问题描述】:

我正在创建一个查询,用于从 teradata 中提取将在 tableau 中使用的数据,我需要修复查询的哪一部分?

我在 Teradata sql 助手中尝试过这个查询,它可以工作,但是当我移动到 tableau 时,它总是以错误 ORDER BY is not allowed in subqueries 结束

在 teradata sql 查询下方:

    Select  
    ChannelType,Group,
    LevelType,
    EXTRACT(YEAR From CDate) as KYear, 
    EXTRACT(MOnth From CDate) as KMonth, 

    Case 
    when Position('Live' IN modeType) >0 then 'L'
    else 'S'
    end as LS,

    Sum(watch) as Watches,
    Sum(amount) as amounts
    zeroifnull(amounts)/zeroifnull(Watches,)as result,

    CASE 
    WHEN result >0 then 'WIN'
    ELSE 'LOSE'
    END AS WL Class

    From Mart_wodo.data where
    CDate between date'2018-01-01' and date'2018-12-31'  and
    Group in('L1','L2','L3','L4','L5') and
    LevelType NOT IN('0') and 
    Channeltype in('TV','TY,'IG')

    Group By Channeltype , Group, LevelType, KYear, KMonth,LS

    Order BY  KYear, KMonth,Channeltype, Group,LS asc

【问题讨论】:

    标签: tableau-api


    【解决方案1】:

    我的猜测是 Tableau 将您的查询包装在外部 SELECT 中,这就是您收到 ORDER BY not allowed 错误消息的原因,但它在 SQL 助手中按原样工作。

    如果是这种情况,您需要删除 ORDER BY 子句并查看是否可以通过 Tableau 指定最终排序。或者可能将您的 SQL 包装在一个视图中并通过 Tableau 访问该视图:link

    作为一个潜在的 hack(它可能不起作用),您可以尝试重新排序 GROUP BY 列或添加带有 ORDER BY 子句的虚拟窗口函数,看看是否有任何效果:

    Select  
      ChannelType,Group,
      ...
      ROW_NUMBER() OVER(ORDER BY KYear, KMonth, Channeltype, Group, LS ASC) AS RowNum
    
    From Mart_wodo.data where
    CDate between date'2018-01-01' and date'2018-12-31'  and
    Group in('L1','L2','L3','L4','L5') and
    LevelType NOT IN('0') and 
    Channeltype in('TV','TY,'IG')
    
    Group By KYear, KMonth, Channeltype, Group, LS, LevelType
    

    【讨论】:

    • 太棒了!别客气。你使用了视图还是ORDER BY hack?如果您使用了 hack,我会小心处理,因为行为可能会在 TD 版本中发生变化,您可能无法 100% 依赖它。
    • 我在你之前建议的虚拟窗口函数中使用“ORDER BY”。 yah 似乎与 TD 版本有关。需要小心它,因为 TDSA 不再可以用作我们想在 tableau 中使用它的查询的标准测试平台
    猜你喜欢
    • 2020-01-25
    • 2012-01-04
    • 1970-01-01
    • 1970-01-01
    • 2015-11-11
    • 2017-04-12
    • 1970-01-01
    • 2015-01-18
    • 2018-09-09
    相关资源
    最近更新 更多