I have the following table
CREATE TABLE "matches" (
"match_id" INTEGER,
"uts" INTEGER
"player_id" INTEGER,
"opponent_id" INTEGER
);
I want to obtain for each match the number of matches the player and opponent have played against each other before that specific match.
uts
represents a timestamp and can be used to filter the data.S.
Let’s assume I have the following data
39943359 1678449600 1 2
39943361 1678449600 3 4
39943363 1678451400 5 6
39943365 1678451400 5 6
39943367 1678453200 5 6
39943369 1678453200 1 3
39943371 1678455000 1 2
39943373 1678455000 1 5
I would expect the following result:
39943359 0
39943361 0
39943363 0
39943365 1
39943367 2
39943369 0
39943371 1
39943373 0
How to include the uts
-condition in
SELECT match_id, COUNT(*)
FROM matches
WHERE rowid NOT IN (
SELECT MIN(rowid)
FROM matches
GROUP BY player_id, opponent_id
)