根据PostgreSQL中的列值指定的间隔 [英] Intervals specified according to column values in PostgreSQL

查看:95
本文介绍了根据PostgreSQL中的列值指定的间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据就是这样

wavelength    reflectance
341.6         2.48
343.6         2.58
347.6         4.51
351.1         8.51
359.2         9.56
362.2         11.2
364.2         25.3
365.3         58.2
366.6         58.2
368.9         24.2
373.6         28.2

我希望采用10个波长间隔,并将它们之间的反射率间隔取平均值,然后输出将为 我想要这样的输出

I wish to take 10 intervals of wavelength and the reflectance intervals in between them is taken average then the output will be I want output like this

wavelength    reflectnce
341.6         2.48
351.1         5.20
362.2         10.38
373.6         32.35

推荐答案

在SQL Server中,您可以这样做:

In SQL Server you can do it like this:

;WITH CTE AS(
SELECT ROW_NUMBER() OVER(PARTITION BY CAST(wavelength AS INT)-CAST(wavelength AS INT)%10 ORDER BY wavelength) AS ROW_ID,wavelength,reflectance FROM Your_Table
)

SELECT wavelength,reflectance FROM CTE WHERE ROW_ID=1

希望这会有所帮助.

这篇关于根据PostgreSQL中的列值指定的间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆