+GROUP BY (TB_1000 * 1000) / $window as TB, GNB_ID
+;
+
+DEFINE{ query_name 'mc_disconnected_gtp_teids';
+ max_lfta_disorder '1'; max_hfta_disorder '1';
+}
+PARAM{ window uint; }
+Select m.TB, m.gTP_TEID, d.GNB_ID, d.connected_time
+LEFT_OUTER_JOIN from mc_disconnected_ues d, gnb_ueid_teid_map m
+where d.GNB_ID=m.GNB_ID and d.UE_ID=m.id_SgNB_UE_X2AP_ID and
+ (d.TB_1000 * 1000) / $window = m.TB
+;
+
+DEFINE{ query_name 'mc_connection_stats_gtp_teid';
+ max_lfta_disorder '1'; max_hfta_disorder '1';
+ comment 'statistics about the length of dual connected sessions, by gtp_teid';
+}
+PARAM{ window uint; }
+SELECT ($window*(TB+1))/1000 as TS, GNB_ID, gTP_TEID,
+ $window/1000.0 as measurementInterval, // standard_name
+ MIN(connected_time)/1000.0 as min_connected_time,
+ MAX(connected_time)/1000.0 as max_connected_time,
+ AVG(connected_time)/1000.0 as avg_connected_time,
+ quantile_of(connected_time, .05)/1000.0 as pctl_05_connected_time,
+ quantile_of(connected_time, .95)/1000.0 as pctl_95_connected_time,
+ sqrt(
+ sum((connected_time/1000.0)*(connected_time/1000.0)) - sum(connected_time/1000.0)*sum(connected_time/1000.0)/count(*)
+ ) / count(*) as stddev_connected_time
+FROM mc_disconnected_gtp_teids
+GROUP BY TB, GNB_ID, gTP_TEID