My input data is like this
wavelength reflectance
341.6 1.15
343.1 1.14
344.7 1.13
346.3 1.14
347.9 1.14
349.5 1.12
351.1 1.12
352.6 1.13
354.2 1.13
I am using this formula Query
WITH CTE AS(
SELECT
ROW_NUMBER() OVER(
PARTITION BY CAST(wavelength AS INT)
-CAST(wavelength AS INT)%5
ORDER BY wavelength) AS ROW_ID,
wavelength,
avg( reflectance ) OVER(
PARTITION BY CAST(wavelength AS INT)
-CAST(wavelength AS INT)%5
ORDER BY wavelength
rows BETWEEN 1 FOLLOWING
and UNBOUNDED FOLLOWING) As reflectance
FROM
test
)
select trunc(wavelength/5)*5 AS wavelengthwavelength, reflectance
from CTE
where row_id = 1
In this query it povides the output like this
wavelength reflectance
340 2.6400000000000000
340 2.5200000000000000
345 2.5200000000000000
355 2.5500000000000000
360 2.4250000000000000
365 2.4650000000000000
365 2.5450000000000000
370 2.4733333333333333
380 2.6600000000000000
385 2.7400000000000000
390 2.7700000000000000
390 2.8833333333333333
In this output 340,365,390 is placed as twice, instead of placed as twice it should be placed as once only based on the min value, how should do this...