sql - MYSQL Query to find changes in count -



sql - MYSQL Query to find changes in count -

i have great sql query (provided helpful foxygen) returns specific subset set of info big set of metrics.

select sum(metric_activesessions), max(metric_timestamp) max_time, min(metric_timestamp) min_time metrics_tbl metric_timestamp > now() - interval 60 min grouping unix_timestamp(metric_timestamp) div 300

i'm trying figure out if can append existing query homecoming adjacent results have major negative difference in value.

for example, if results are:

1. 2334 @ 12:01 2. 2134 @ 12:05

in scenario, result 2 has changed count -100.

thanks in advance guidance.

mitch

you can calculate difference using variables in mysql:

select s, max_time, min_time, (case when (@x := @sprev) null null when (@sprev := s) null null else @x end) sprev (select sum(metric_activesessions) s, max(metric_timestamp) max_time, min(metric_timestamp) min_time metrics_tbl metric_timestamp > now() - interval 60 min grouping unix_timestamp(metric_timestamp) div 300 ) t cross bring together (select @sprev := null) vars order max_time;

you can test whatever difference using having clause:

having s - sprev >= 100

or whatever.

mysql sql

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -