Tableau api 将SQL查询转换为Tableau

Tableau api 将SQL查询转换为Tableau,tableau-api,Tableau Api,我正在尝试将以下SQL查询转换为Tableau: select store1.name, store1.city, store1.order_date from store1 where order_date = (select max(store2.order_date) from store2 where store2.name = store1.name and store2.city = store1.ci

我正在尝试将以下SQL查询转换为Tableau:

select store1.name, store1.city, store1.order_date
from store1
where order_date = (select max(store2.order_date) from store2 
                    where store2.name = store1.name
                    and store2.city = store1.city)
我对Tableau很陌生,无法理解如何翻译where子句,因为它是从另一个表中选择的

例如,给定以下表格

商店1:

Name | City | Order Date Andrew | Boston | 23-Aug-16 Bob | Boston | 31-Jan-17 Cathy | Boston | 31-Jan-17 Cathy | San Diego | 19-Jan-17 Dan | New York | 3-Dec-16 名称|城市|订单日期 安德鲁|波士顿| 2016年8月23日 鲍勃·波士顿2017年1月31日 凯西波士顿2017年1月31日 Cathy|San Diego|17年1月19日 丹|纽约| 2016年12月3日 商店2:

Name | City | Order Date Andrew | Boston | 2-Sep-16 Brandy | Miami | 4-Feb-17 Cathy | Boston | 31-Jan-17 Cathy | Boston | 2-Mar-16 Dan | New York | 2-Jul-16 名称|城市|订单日期 安德鲁|波士顿| 2016年9月2日 布兰迪|迈阿密| 2017年2月4日 凯西波士顿2017年1月31日 凯西波士顿2016年3月2日 丹|纽约| 2016年7月2日 我的查询将从存储1返回以下内容:

Name | City | Order Date Bob | Boston | 31-Jan-17 Cathy | Boston | 31-Jan-17 名称|城市|订单日期 鲍勃·波士顿2017年1月31日
Cathy | Boston | 31-Jan-17逐点,将SQL查询转换为Tableau自定义SQL查询将是:

SELECT [Store1].[Name], [Store1].[City], [Store1].[Order Date]
FROM [Store1]
WHERE [Order Date] = (SELECT MAX([Store2].[Order Date]) FROM [Store2]
                      WHERE [Store2].[Name] = [Store1].[Name]
                      AND [Store2].[City] = [Store1].[City])

在预览中,您会注意到它只返回Cathy。但是,一旦您在订单日期将SQL查询加入到主表中,您将看到预期的Bob和Cathy。

逐点,将该SQL查询转换为Tableau自定义SQL查询将是:

SELECT [Store1].[Name], [Store1].[City], [Store1].[Order Date]
FROM [Store1]
WHERE [Order Date] = (SELECT MAX([Store2].[Order Date]) FROM [Store2]
                      WHERE [Store2].[Name] = [Store1].[Name]
                      AND [Store2].[City] = [Store1].[City])

在预览中,您会注意到它只返回Cathy。但是,一旦您在订单日期将SQL查询加入到主表中,您将看到Bob和Cathy,正如您所期望的那样。

感谢您提供了起点-我设法让自定义查询返回Bob和Cathy的单个实例(日期为2017年1月31日)通过稍微修改您的解决方案并将与store1的内部联接直接添加到子查询中,我成功地通过稍微修改您的解决方案并将与store1的内部联接直接添加到子查询中,使自定义查询返回bob和cathy的单个实例(日期为2017年1月31日)