【问题标题】:How to combine input from two records into one output record?如何将两条记录的输入合并为一条输出记录?
【发布时间】:2021-11-05 15:44:05
【问题描述】:

我正在生成一份报告,显示工厂一天运行了多长时间。

由于操作员在午餐时间关闭系统,我有 2 条每天的工厂运行时间记录。我只想显示一条记录,其中包含生产开始时间(上午 6:00)和生产结束时间(下午 4:00 左右)。我有一个表Runtime_Combined,它有一个自动递增的索引。

我想选择开始日期(例如9/1/2021 6:04 AM,其中runtime_combined_ndx = 1)和结束日期(例如9/1/21 4:23 PM,其中有runtime_combined_ndx = 2)。

SELECT ProductionStartDate, ProductionEndDate  
FROM Runtime_Combined     
WHERE month(ProductionStartDate) = month (ProductionStartDate)     
And day(ProductionStartDate) = day( ProductionStartDate) 

【问题讨论】:

标签: mysql sql database ignition scada-ignition


【解决方案1】:

你可以使用聚合:

SELECT date(ProductionStartDate), sum(runtime_combined_ndx)  
FROM Runtime_Combined     
GROUP BY date(ProductionStartDate);

【讨论】:

    【解决方案2】:

    使用分组。比如:

    SELECT MIN(ProductionStartDate) AS Start, MAX(ProductionEndDate) As End
    FROM Runtime_Combined
    WHERE <....>
    GROUP BY DATE(ProductionStartDate)
    

    【讨论】:

      猜你喜欢
      • 2017-02-24
      • 1970-01-01
      • 2021-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-26
      • 1970-01-01
      相关资源
      最近更新 更多