I have a table with the following data
PKey Start End Type
==== ===== === ====
01 01/01/2010 14/01/2010 S
02 15/01/2010
In MySQL you basically need:
SELECT COUNT(*)
FROM date_ranges AS A, date_ranges AS B
WHERE A.id <> B.id
AND A.id > B.id
AND A.end_at > B.start_at
AND B.end_at > A.start_at
> in the second and the third statement can be replaced with >= to follow includes matching.
This topic is related to the "Allen's Interval Algebra" and there are some more reading on this can be found by those links: