首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取相同时间戳postgres的不同值

获取相同时间戳postgres的不同值
EN

Stack Overflow用户
提问于 2017-07-13 19:24:43
回答 1查看 163关注 0票数 0

对于相同的时间戳,我有2种不同的类型和一个合计的值。我想创建一个检索时间戳、value1、value2的查询,其中value1是type1的总数,value2是type2的总数。

我的sum字段是一个数字[],但在我正在处理的类型中只有一个值。在其他情况下,是一个具有不同值的数组。

我试过了:

代码语言:javascript
复制
select distinct type, timestamp, sum 
from default_dataset 
where type like 'probing_%' 
group by type, timestamp, sum 
limit 10

正在做什么

代码语言:javascript
复制
select timestamp, type, sum 
from default_dataset 
where type like 'probing_%' 
order by timestamp desc 
limit 50

我有过

代码语言:javascript
复制
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

我想要一个像timestamp,type,sum(sum)这样的结果

代码语言:javascript
复制
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

有没有人?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-13 19:42:20

你试过sum1吗?..如下所示:

代码语言:javascript
复制
select timestamp, type, sum(sum[1])
from default_dataset 
where type like 'probing_%' 
group by "timestamp", "type" 
limit 50

要将所有内容放在一列中,只需查看结果:

代码语言:javascript
复制
with a as (
select timestamp a, type b, sum(sum[1]) c
from default_dataset 
where type like 'probing_%' 
group by "timestamp", "type" 
)
select concat(a,' ',b,' ',c) from a
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45079222

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档