나는 이런 종류의 쿼리에서 timescaleDB 특별한 time_bucket () 메서드를 사용합니다.
SELECT time_bucket('**1 day**', time) AS datetime, temp.inside_t FROM temp where serial in ('77777777777', '77777777778') and time > '2020-**02-03** 13:54:46.768000' and time < '2020-**03-04** 13:53:46.768000' GROUP BY datetime ORDER BY datetime DESC;
또는
SELECT time_bucket('**1 hour**', time) AS datetime, temp.inside_t FROM temp where serial in ('77777777777', '77777777778') and time > '2020-**03-03** 13:54:46.768000' and time < '2020-**03-04** 13:53:46.768000' GROUP BY datetime ORDER BY datetime DESC;
쿼리 시간과 예상 포인트 수량에 따라 적절한 시간 ( 1 일 또는 6 시간 , 15 분 )을 수동으로 계산 해야합니다.
제 경우에는 쿼리의 시간 창을 측정하고 예상되는 포인트 수량을 보낼 수 없습니다 . 예를 들어 100 포인트 를 받고 싶습니다 .
SELECT time_bucket(**100**) AS datetime, temp.inside_t FROM temp where serial in ('77777777777', '77777777778') and time > '2020-02-03 13:54:46.768000' and time < '2020-03-04 13:53:46.768000' GROUP BY datetime ORDER BY datetime DESC;
또는 time_bucket ()에 대한 적절한 대안 .
나는이 기사를 읽었 지만 흥미로운 벌금을 부과하지 않았다.
간단한 해결책은 Grafana 작업 방법을 살펴 보는 것에서 나왔습니다. 에서 빼고 원하는 점수로 나누어야하므로 원하는 점수를 얻을 수있는 시간 (초)을 결정하십시오.
List get(long from, long until, long maxDataPoints) {
final String query = String.format("SELECT time_bucket('%s seconds', time) AS dateTime, avg(temp.inside), avg(temp.outside) FROM temp where serial in ('777777777') and time > '2020-03-03 13:54:46.768000' and time < '2020-03-04 13:54:46.768000' GROUP BY dateTime ORDER BY dateTime DESC;",
round((until - from) / maxDataPoints));
return jdbcTemplate.query(query, new RowMapper());
여기서 BTW는 또 다른 유용한 방법 입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다