简体   繁体   English

计算两次之间的分钟数,然后除以记录量

[英]Calculating amout of minutes between 2 times and divide it by amount of records

How can we calculate the amount of minutes between 9 and 11 of all the records togther (colum is generated). 我们如何计算所有记录之间的9到11分钟之间的分钟数(生成列)。 I also want to know how I can devide the output of that by the amount of records there are. 我也想知道如何根据记录的数量来分配输出结果。

select  address,
        min(from_unixtime(time)) "Aankomsttijd",
        max(from_unixtime(time)) "Eindtijd",
        TIMESTAMPDIFF(MINUTE, min(from_unixtime(time)), max(from_unixtime(time))) "Minuten"
from    sensordata1
Where   from_unixTime(sensordata1.time) BETWEEN '2017/04/04' AND '2017/04/05' AND
        from_unixTime(sensordata1.time, '%H') BETWEEN 9 AND 11
group by address  
having Minuten > 2 AND Minuten < 1400

Output 输出量

Normal database as you can see "Minuten is not a real column" 正常数据库,您可以看到“ Minuten不是真实的列”

What I want to get is all the minutes together as 1 amount and I want that to devide by the amount of records they calculated the minutes together. 我想要得到的是所有分钟的总和为1,而我希望通过他们计算分钟的总记录数来表示。

You can use that query you wrote as source for the calculation you want, like 您可以使用您编写的查询作为源来进行所需的计算,例如

select  sum(Minuten) total_minuten,
        count(*) records,
        sum(Minuten) / count(*) average_minuten
from    (
            select  address,
                    min(from_unixtime(time)) "Aankomsttijd",
                    max(from_unixtime(time)) "Eindtijd",
                    TIMESTAMPDIFF(
                      MINUTE,
                      min(from_unixtime(time)),
                      max(from_unixtime(time))
                    ) "Minuten"
            from    sensordata1
            Where   from_unixTime(sensordata1.time) BETWEEN '2017/04/04' AND '2017/04/05' AND
                    from_unixTime(sensordata1.time, '%H') BETWEEN 9 AND 11
            group by address  
            having Minuten > 2 AND Minuten < 1400
        ) t1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM