Taka jest struktura bazy :
CREATE TABLE "detections"(
device_id INT,
frame_content TEXT,
height INT,
id INT,
latitude REAL,
lonngitude REAL,
team_id INT,
timestamp INT,
user_id INT,
visible TEXT,
width INT,
x INT,
y INT
)
Poszukuję rekordów/zdarzeń z tej samej sekundy.
Poniższy kod rzekomo to robi, ale cholernie długo pracuje (na 350000 rekordów w bazie) .
SELECT datetime(a.timestamp/1000,"unixepoch") as Date,a.device_id,b.device_id
FROM detections a
JOIN (SELECT device_id, timestamp, COUNT(*)
FROM detections
GROUP BY (timestamp ), device_id
HAVING count(*) > 2) b
ON
( (a.timestamp/1000 = b.timestamp/1000 ) and (a.device_id<> b.device_id))
ORDER BY datetime(a.timestamp/1000,"unixepoch")
A najbardziej interesuje mnie by jeśli zostanie znaleziony np.Triplet (lub większy) żeby mieć informację o wszystkich Device_ID, a powyższy kod wyrzuca zawsze 2.
Prosiłbym o ulepszenie kodu :)