I've a simple SQL table which looks like this-
CREATE TABLE msg (
from_person character varying(10),
from_location character varying(10),
to_person character varying(10),
to_location character varying(10),
msglength integer,
ts timestamp without time zone
);
I want to find out for each row in the table if a different 'from_person' and 'from_location' has interacted with the 'to_person' in the current row in last 3 minutes.
For example, in above table, for row # 4, other than mary from Mumbai (current row), nancy from NYC and bob from Barcelona has also sent a message to charlie in last 3 minutes so the count is 2.
Similarly, for row#2, other than bob from Barcelona (current row), only nancy from NYC has sent a message to charlie in ca (current row) so the count is 1
Example desired output-
0
1
0
2
I tried using window function but it seems that in frame clause I can specify rows count before and after but I can't specify a time itself.