Maybe try something like this I think. You would need to replace the temp table declaration with a the SQL Lite equivalent. Also you may need to cast your values to decimals where for instance if p2.TimeMs - p1.TimeMs < 10000 you would get zero returned if the data is stored as integers.
declare @buckets table
(
BucketID int
TimeBucket int,
BucketDesc varchar(50)
)
insert @buckets(bucket)
values(1,10,'0-10'),
--....all values - could populate other values using distinct set of buckets from below
select A.TimeBucket, B.*
from @buckets B
left join
(
SELECT (p2.TimeMs - p1.TimeMs)/(1000*10)+1 AS TimeBucket, COUNT(p2.Passenger - p1.Passenger) AS Separated
FROM Passenger p1
JOIN Passenger p2 ON p1.passenger = p2.passenger
WHERE p1.Event= 0 AND p2.Event= 1 //0 is for arriving at the station and 1 is for the ending of the waiting time
GROUP BY TimeBucket
) D
on B.TimeBucket = D.TimeBucket
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…