SQL 在 Aginity 中运行,但在 Tableau 10.1 中作为自定义查询被拒绝

Posted

技术标签:

【中文标题】SQL 在 Aginity 中运行,但在 Tableau 10.1 中作为自定义查询被拒绝【英文标题】:SQL Running in Aginity but Rejected as Custom Query in Tableau 10.1 【发布时间】:2017-12-20 23:36:59 【问题描述】:

我可以在 Aginity SQL 编辑器中运行下面的查询并获得结果 Redshift 但是当我尝试使用与自定义 sql 相同的查询来生成 Tableau 报告时,我收到一条错误消息,提示“Redshift ODBS 错误试图在第 23 行或附近执行 SQL.Syntax 错误;并且 trans_amt

WITH cons_dedup AS
(SELECT DISTINCT * FROM shop.consumer)
SELECT 
MAX(trans_amt) OVER (PARTITION BY trans.cardid) as max_transaction_for_card,
85 as full_tank,
trans_amt/MAX(trans_amt) OVER (PARTITION BY trans.cardid) as pct_of_max_transaction_for_card,
(CASE WHEN trans_amt/MAX(85) OVER (PARTITION BY trans.cardid) >= .6 THEN 'A'
WHEN trans_amt/MAX(85) OVER (PARTITION BY trans.cardid) >= .2 and trans_amt/MAX(85) OVER (PARTITION BY trans.cardid) <.6 THEN 'B'
WHEN trans_amt/MAX(85) OVER (PARTITION BY trans.cardid) >= 0 and trans_amt/MAX(85) OVER (PARTITION BY trans.cardid) <.2 THEN 'C'
ELSE 'Unknown' END) AS trans_category,
COUNT(*) OVER (PARTITION by trans.cardid) as cnt_trans_for_card,
MIN(transaction_date) OVER (PARTITION BY trans.cardid) as timestamp_of_first_trans_for_card,
LAG(transaction_date, 1) OVER (PARTITION BY trans.cardid ORDER BY transaction_date) as prev_trans_timestamp_for_card,
LEAD(transaction_date, 1) OVER (PARTITION BY trans.cardid ORDER BY transaction_date) as next_trans_timestamp_for_card,
DATEDIFF(day, LAG(transaction_date, 1) OVER (PARTITION BY trans.cardid ORDER BY transaction_date), transaction_date) as days_since_last_trans_for_card,
DATEDIFF(day, transaction_date, LEAD(transaction_date, 1) OVER (PARTITION BY trans.cardid ORDER BY transaction_date)) as days_until_next_trans_for_card,
DATEDIFF(day, transaction_date, MIN(transaction_date) OVER (PARTITION BY trans.cardid)) as days_since_first_trans,
trans.*,
cons.fullname 
FROM x.transaction trans
INNER JOIN cons_dedup cons
ON trans.cardid = cons.cardid
WHERE transaction_desc LIKE 'Transaction Approved (Pre-authorization Advice%'
AND cons.fullname NOT IN ('SYZ', 'TTT')
AND trans_amt <= 85 and trans_amt >= 3;

【问题讨论】:

大概您的两个表中的一个表中有一个名为 trans_amt 的列,对吧?什么是列数据类型? 尝试从末尾删除; - 根据我的经验,这有时会导致 Tableau 出现问题。 【参考方案1】:

从查询中删除终止符(; 在结尾)

【讨论】:

哇,好用!我不敢相信那是多么简单。谢谢!!

以上是关于SQL 在 Aginity 中运行,但在 Tableau 10.1 中作为自定义查询被拒绝的主要内容,如果未能解决你的问题,请参考以下文章

在 Aginity Workbench SQL 中选择 1% 的样本

如何从 Aginity 工作台检查在 IBM Netezza SQL 中处理表的数据和时间?

从 Python 到 SQL(Aginity、Netezza)的 CREATE/DROP 调用不起作用

如何从 Aginity 工作台检查在 IBM Netezza SQL 中创建表的数据和时间

Win7 上 Aginity 工作台对 IBM netezza SQL 数据库的 SQL 查询错误

在 Netezza (Aginity) 中安装 UDF