【问题标题】:MS Report Builder Min and Max Date in Table by Record ID表中的 MS Report Builder 最小和最大日期(按记录 ID)
【发布时间】:2021-04-30 14:27:55
【问题描述】:

我正在使用一个数据库,该数据库存储在特定时间段内与我的雇主打交道的个人的记录,他们的记录每 10 天左右更新一次。但数据库不存储他们的初始订婚日期,除非在初始记录中。我需要使用 Microsoft Report Builder 3.0 生成一个表格,其中显示一个人的所有记录和初始参与日期。

这是我的简单 SELECT 查询返回的示例。 (而且它们确实是简单的查询——从一张表中选择大约六个字段,其中一个条件为真。)

Customer ID Session Date Record Created Date
5678 4/1/2019 4/4/2019
5678 4/1/2019 4/24/2019
5678 4/1/2019 5/5/2019
5678 4/1/2019 5/25/2019
5678 4/1/2019 6/6/2019
5678 4/1/2019 6/26/2019
5678 10/8/2020 10/10/2020
5678 10/8/2020 10/30/2020
5678 10/8/2020 11/21/2020
5678 10/8/2020 12/01/2020
54321 7/7/2020 7/9/2020
54321 7/7/2020 7/29/2020
54321 7/7/2020 8/8/2020
54321 7/7/2020 8/28/2020
54321 7/7/2020 9/7/2020
54321 7/7/2020 9/27/2020

这是我想要结果的示例。

Customer ID Session Date Record Created Date Min Created Max Created
5678 4/1/2019 4/4/2019 4/4/2019 6/26/2019
5678 4/1/2019 4/24/2019 4/4/2019 6/26/2019
5678 4/1/2019 5/5/2019 4/4/2019 6/26/2019
5678 4/1/2019 5/25/2019 4/4/2019 6/26/2019
5678 4/1/2019 6/6/2019 4/4/2019 6/26/2019
5678 4/1/2019 6/26/2019 4/4/2019 6/26/2019
5678 10/8/2020 10/10/2020 10/10/2020 12/01/2020
5678 10/8/2020 10/30/2020 10/10/2020 12/01/2020
5678 10/8/2020 11/21/2020 10/10/2020 12/01/2020
5678 10/8/2020 12/01/2020 10/10/2020 12/01/2020
54321 7/7/2020 7/9/2020 7/9/2020 9/27/2020
54321 7/7/2020 7/29/2020 7/9/2020 9/27/2020
54321 7/7/2020 8/8/2020 7/9/2020 9/27/2020
54321 7/7/2020 8/28/2020 7/9/2020 9/27/2020
54321 7/7/2020 9/7/2020 7/9/2020 9/27/2020
54321 7/7/2020 9/27/2020 7/9/2020 9/27/2020

我能够在 Business Objects 中实现这一目标,方法是使用一个连接客户 ID 和会话日期字段的变量,然后使用这些表达式添加另外两个变量: =Min([Submitted Date]) In ([ConcatenateCustomerSession]) =Max([Submitted Date]) In ([ConcatenateCustomerSession])

有什么想法吗?如果可以的话,我更愿意将其作为计算字段来执行,只是因为我更喜欢表达式而不是 SQL 代码,但在这一点上,我会尽一切努力完成工作。

【问题讨论】:

    标签: sql max reportbuilder3.0 calculated-field maxdate


    【解决方案1】:

    这在 SQL 中很简单。在现有的 select 语句中添加另外两列

    ,Min([Record Created Date]) Over (Partition by [Customer ID]) as [Min Created]
    ,Max([Record Created Date]) Over (Partition by [Customer ID]) as [Max Created]
    

    【讨论】:

    • 看OP想要的输出,好像分区应该是[Customer ID],[Session Date]
    • 就是这样!有效!感谢你们,Chris 和 Jayvee!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-24
    • 2012-07-16
    • 1970-01-01
    • 2012-02-12
    • 1970-01-01
    • 2012-05-16
    相关资源
    最近更新 更多