diff --git a/src/main/java/it/pagopa/interop/probing/statistics/api/service/impl/TimestreamServiceImpl.java b/src/main/java/it/pagopa/interop/probing/statistics/api/service/impl/TimestreamServiceImpl.java index 73d9fea..6b8f983 100644 --- a/src/main/java/it/pagopa/interop/probing/statistics/api/service/impl/TimestreamServiceImpl.java +++ b/src/main/java/it/pagopa/interop/probing/statistics/api/service/impl/TimestreamServiceImpl.java @@ -77,8 +77,8 @@ public List findStatistics(Long eserviceRecordId, Integer poll + "SELECT binned_timestamp, status, avg_response_time " + "FROM " //this select with the where condition on seqnum deletes all the duplicates time that will be created with the approximation keeping the lowest time - + "(SELECT * , row_number() over (partition by binned_timestamp order by binned_timestamp desc) as seqnum FROM " - + "(SELECT eservice_record_id ,status,bin(time,"+ (pollingFrequency * months) +"m) as binned_timestamp, cast(avg(response_time) as int) as avg_response_time " + + "(SELECT * , row_number() over (partition by binned_timestamp order by binned_timestamp desc,num_status desc) as seqnum FROM " + + "(SELECT eservice_record_id ,status,bin(time,"+ (pollingFrequency * months) +"m) as binned_timestamp, cast(avg(response_time) as int) as avg_response_time,count(status) as num_status " + "FROM " + database + "." + table + " " + "WHERE time between " + (Objects.nonNull(startDate) ? "'" + startDate.format(DateTimeFormatter.ofPattern(TIME_FORMAT)) + "' " : "ago(1d) ")