--Query 07: "Plot CDF of packet delays from minimum to 500 msec (for one
-- PathSpec one day)"

--ProbesPerDelay: Group probes for a NodePairId or a day into delays < 500mSec

--TotalProbes: Count the total number of probes in a day for a NodePairId

WITH \
-- A list of probes with a certain delay < 500 mSec
ProbesPerDelay (Delay, NumProbes) as \
( \
SELECT	(t.Delay/1000 + 1) as Delay, count(*) as NumProbles \
FROM	Surveyor.Times t \
WHERE	t.Delay != -1 AND \
	t.NodePairID = 1 AND \
	t.start BETWEEN (954633600) AND (954633600 + 86400 - 1) AND \
	(t.Delay/1000 + 1) <= 500 \
GROUP BY	(t.Delay/1000 + 1) \
), \
-- The total num of probles in the day
TotalProbes (Probes) as ( \
SELECT	count_big(*) \
FROM	Surveyor.Times t \
WHERE	t.NodePairID = 1 AND \
	t.start BETWEEN (954633600) AND (954633600 + 86400 - 1) \
) \
SELECT	pd.Delay as "mSec Delay", sum(tmp.NumProbes) as "Cumulative" , \
	tp.Probes as "Total" \
FROM	ProbesPerDelay pd, TotalProbes tp, ProbesPerDelay tmp \
WHERE	tmp.Delay <= pd.Delay \
GROUP BY	pd.Delay, tp.Probes \
ORDER BY pd.Delay
