【发布时间】:2017-07-13 11:24:42
【问题描述】:
对于相同的时间戳,我有 2 种不同类型的总值。我想创建一个检索时间戳、value1、value2 的查询,其中 value1 是 type1 的总和,而 value2 是 type2 的总和。
我的 sum 字段是一个数字 [],但我正在处理的类型中只有一个值。在其他情况下是一个具有不同值的数组。
我试过了:
select distinct type, timestamp, sum
from default_dataset
where type like 'probing_%'
group by type, timestamp, sum
limit 10
在做
select timestamp, type, sum
from default_dataset
where type like 'probing_%'
order by timestamp desc
limit 50
我有
2017-07-13 12:24:38+01 | probing_repated | 50
2017-07-13 12:24:38+01 | probing_live | 10
2017-07-13 12:24:38+01 | probing_live | 15
2017-07-13 12:24:38+01 | probing_repated | 10
2017-07-13 12:19:00+01 | probing_live | 11
2017-07-13 12:19:00+01 | probing_repeated | 40
2017-07-13 12:19:00+01 | probing_repeated | 21
2017-07-13 12:19:00+01 | probing_live | 26
我想要时间戳、类型、总和(总和)等结果
2017-07-13 12:24:38+01 | probing_repated | 65
2017-07-13 12:24:38+01 | probing_live | 25
2017-07-13 12:19:00+01 | probing_live | 37
2017-07-13 12:19:00+01 | probing_repeated | 61
有人吗?
【问题讨论】:
-
提示:
GROUP BY timestamp, type
标签: sql postgresql