BIRT:计算时间间隔的平均值
我有以下由一系列任务组成的数据库表:
id BIGINT NOT NULL
time_in timestamp(0) with time zone,
time_out timestamp(0) with time zone,
user_name text NOT NULL
我将任务的持续时间计算为(time_out - time_in)。我需要首先计算给定用户的平均任务持续时间,然后计算所有用户的平均任务持续时间。
我首先在 SQL 查询中执行用于获取数据集的操作。其结果是 INTERVAL,但在 BIRT 中它被视为字符串(可能是因为缺少 INTERVAL 数据类型)。
所以现在我有一组字符串,每个字符串代表一个间隔。我如何计算他们的平均值?
PS 我首先想到应该使用 BIRT“时间”数据类型来完成此操作。然而,“时间”代表一天中的某个时间,而不是一个时间间隔。 BIRT 中的 INTERVAL 似乎没有等效项。
I have the following database table consisting of a series of tasks:
id BIGINT NOT NULL
time_in timestamp(0) with time zone,
time_out timestamp(0) with time zone,
user_name text NOT NULL
I compute the duration of a task as (time_out - time_in). I need to first compute the average task duration for a given user, and afterwards for all users.
I do the first within the SQL query used to obtain the data set. The result of this is an INTERVAL, but in BIRT it is seen as a String (maybe because the INTERVAL data type is absent).
So now I have a set of Strings, each representing an INTERVAL. How do I compute their average?
P.S. I first thought I should do this by using the BIRT 'Time' data type. However, 'Time' represents a time of day, not an interval. There seems to be not equivalent for INTERVAL in BIRT.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您尝试过 avg 聚合函数吗?
从任务中选择 avg(time_out - time_in) 作为 user_avg WHERE user_name='bob';
从任务中选择 avg(time_out - time_in) 作为 all_avg;
Have you tried the avg aggregate function?
SELECT avg(time_out - time_in) as user_avg FROM tasks WHERE user_name='bob';
SELECT avg(time_out - time_in) as all_avg FROM tasks;
不熟悉 birt,但我认为最好的方法是让 PostgreSQL 来做。定义一个进行平均的视图,然后从中选择。
Not familiar with birt, but I'd think the best way would be to let PostgreSQL do it. Define a view that does your averaging, and just SELECT from it.