我有一张具有以下结构的桌子。
+ ----------------------+--------------+--------+---------+
| timeStamp | value | type | id |
+ ----------------------+--------------+--------+---------|
| '2010-01-14 00:00:00' | '11787.3743' | 'mean' | 1 |
| '2018-04-03 00:07:21' | '9.9908' | 'std' | 1 |
| '2018-04-03 00:10:00' | '11787.3743' | 'min' | 1 |
+ ----------------------+--------------+--------+---------+
现在我想写一个select查询,我可以根据类型获取数据。
在这里你可以看到我只希望数据间隔10分钟而且'mean_type'/'min_type'/'std_type'列应该是动态的,应该使用concat查询(id,'_ ”, '平均')
+ ----------------------+--------------+-------------+----------+
| timeStamp | 1_mean | 1_min | 1_std |
+ ----------------------+--------------+-------------+----------+
| '2010-01-14 00:00:00' | '11787.3743' | | |
| '2018-04-03 00:10:00' | | '11787.3743 | |
+ ----------------------+--------------+-------------+----------+
我使用了以下查询,但它无效: -
查询: -
select
to_timestamp(floor((extract('epoch' from m.timeStamp) / 600 )) * 600)
AT TIME ZONE 'UTC' as t,
case type when 'mean' then value end as concat(id,'mean'),
case type when 'min' then value end as concat(id,'min'),
case type when 'std' then value end as concat(id,'std'),
from measure m
where id=1
GROUP by t
order by t;
我正在使用postgres DB。