返回冲突结果的最小(日期) - Tableau

Min(date) returning conflicting Results - Tableau

长期观察者,第一次张贴者:

我目前正在使用 Tableau 中的 SQL 功能。我想查询 return 用户 ID (SQLCEC)、出席日期 (SQL 日期) 以及该用户第一次出席 (FirstAttendanceDate)。

SELECT [Attendees$].[CEC] AS [SQLCEC]

, [Attendees$].[Date] AS [SQL Date]
, [Data2].[FirstAttendanceDate]       

FROM [Attendees$]
INNER JOIN(SELECT [Attendees$].[Name]
,                  MIN([Attendees$].[Date])As [FirstAttendanceDate]
                   From [Attendees$]
                   Group By [Attendees$].[Name])AS [Data2]
ON [Attendees$].[Name] = [Data2].[Name]
WHERE [Attendees$].[CEC] IN ("jakyles","ajannett")
ORDER BY [Attendees$].[CEC],[Attendees$].[Date]

代码return结果如下:

SQLCEC    SQL Date          FirstAttendanceDate
ajannett  12/9/2014 0:00    12/9/2014 0:00
ajannett  4/14/2015 0:00    12/9/2014 0:00
ajannett  6/23/2015 0:00    12/9/2014 0:00
jakyles   12/9/2014 0:00    12/9/2014 0:00
jakyles   5/12/2015 0:00    12/9/2014 0:00
jakyles   6/23/2015 0:00    6/23/2015 0:00

我想弄清楚为什么我的 FirstAttendanceDate 列对用户 jackyles 是 returning“6/23/2015”(这不是我想要的),而用户 ajannett 是 return荷兰国际集团期望的结果。我是 SQL 的新用户。我从根本上错过了什么吗?感谢您的帮助!

我的猜测,没有看到您的原始表格,与 Name 列的内容有关,而不是 CEC 列。我怀疑如果您将名称列添加到结果集中,最后两行的该列的内容对于名称列将是不同的,即使它们对于 SQLCEC 列是相同的。

我唯一的建议是将查询中的引用从名称更改为 CEC:

SELECT [Attendees$].[CEC] AS [SQLCEC]
, [Attendees$].[Date] AS [SQL Date]
, [Data2].[FirstAttendanceDate]       

FROM [Attendees$]
INNER JOIN(SELECT [Attendees$].[CEC]
,                  MIN([Attendees$].[Date])As [FirstAttendanceDate]
                   From [Attendees$]
                   Group By [Attendees$].[CEC])AS [Data2]
ON [Attendees$].[CEC] = [Data2].[CEC]
WHERE [Attendees$].[CEC] IN ("jakyles","ajannett")
ORDER BY [Attendees$].[CEC],[Attendees$].[Date]

我想通了。

SELECT [Attendees$].[CEC] AS [SQLCEC]

, [Attendees$].[Date] AS [SQL Date]
, [Data2].[FirstAttendanceDate]       

FROM [Attendees$]
INNER JOIN(SELECT [Attendees$].[CEC]
,                  MIN([Attendees$].[Date])As [FirstAttendanceDate]
                   From [Attendees$]
                   Group By [Attendees$].[CEC])AS [Data2]
ON [Attendees$].[CEC] = [Data2].[CEC]
WHERE [Attendees$].[CEC] IN ("jakyles","ajannett")
ORDER BY [Attendees$].[CEC],[Attendees$].[Date]

我是以名义加入的,而不是 CEC。