【问题标题】:Different date/time values in 1 dataset1 个数据集中的不同日期/时间值
【发布时间】:2020-12-16 04:56:14
【问题描述】:

我正在为以下情况寻找解决方案:

在此列表中,我需要定义 3 列,1 列带有名称,1 列带有最新日期/时间登录,1 列带有最新日期/时间注销。

FEX:

姓名 |日期 |约会
汤姆 | 25/08 | 27/08

我有一个包含用户信息的表和一个包含移动信息的表,我加入了。

要获取日期的正确日期,代码如下所示

Select
Employee_name
max([Date Action]) as "Date IN",
From
[employee]  left join [Movement] .... 
where
[Move Type] = 0 ( = IN ) 
[Status] = 2 ( = Active )
Group by 
Employee_name;

如何将最新的 DATE OUT 数据添加到数据集中?

在哪里

[移动类型] = 1 ( =OUT )

[状态] = 3

谢谢。

【问题讨论】:

    标签: datetime dataset where-clause


    【解决方案1】:

    你可以实现它的对

    Select
    Employee_name
    max([Date Action]) as "Date OUT",
    From
    [employee]  left join [Movement] .... 
    where
    [Move Type] = 1 ( = OUT ) 
    [Status] = 2 ( = Active )
    Group by 
    Employee_name;
    

    JOIN 两人在一起。在我习惯的 RDBMS 中,它看起来像

    select t.Employee_name, t.[Date IN], t2.[Date OUT]
    from
    (
        Select
        Employee_name
        max([Date Action]) as "Date IN",
        From
        [employee]  left join [Movement] .... 
        where
        [Move Type] = 0 
        [Status] = 2
        Group by 
        Employee_name
    ) t
    (    Select
        Employee_name
        max([Date Action]) as "Date OUT",
        From
        [employee]  left join [Movement] .... 
        where
        [Move Type] = 1 
        [Status] = 2
        Group by 
        Employee_name
    ) t2
    on t.Employee_name = t2.Employee_name;
    

    【讨论】:

      猜你喜欢
      • 2015-04-26
      • 2016-09-09
      • 1970-01-01
      • 1970-01-01
      • 2011-05-20
      • 2019-10-28
      • 2021-08-22
      • 1970-01-01
      • 2017-01-16
      相关资源
      最近更新 更多