the database is postgresql. Table table shows the conditional data of several intervals of A _ Magi B ~ C ~ D,
1, finding the intersection of A _ mai B?
2. Find the intersection of Amurc, which is not in the B interval.
3. Find the intersection of Amurd and not in Bmurc?
currently using query statement: select a.name from (select distinct name from table where A) as a join (select distinct name from table where B) as b on a.name = b.name
the amount of data is about 6000W, which is currently queried by subquery and then Join. But the query time is long, is there any other better solution?
= actual business =
an order table that queries users who have orders 30 or 60 days before a certain date (a cycle).
demand 1, with orders in 30-60 days (previous cycle)
demand 2, no orders in 30-60 days (previous cycle), orders in 60-90 (first 2 cycles)