Oracle/SQL: Split two inter-related lists into independent cohorts

倾然丶 夕夏残阳落幕 提交于 2019-12-12 04:46:12

问题


Say I have a table TB1, for the conditions defined, the list below is unique. The products and emails is Many-to-Many relationship.

I am going to do a survey for the products consumers purchased.

Product   Email  
TV        a@server.com  
Fridge    a@server.com 
Fridge    b@server.com 
TV        c@server.com  
Cooler    c@server.com

The requirements are:

  1. Each product couldn't be assigned to 2 surveys. Each survey could have multiple products. All customers who have purchased this product should be in the same survey.

  2. Each customer couldn't be assigned to 2 surveys. Each survey could have multiple emails assigned. Each survey is sent to one person, asking how do you like the products listed.

  3. This list is big. The problem is the email server could only handle, say 3000 emails at once. In the cases when there are 7000 unique emails(each email is asking question about all the products the customer bought) to be sent, three SurveyIDs needs to be created. It doesn't mean each has 3000 emails, but it has to meet requirement 1 and 2.

Note: each customer could buy at most 10 products.

Question: How to find out the cohorts of the (product,email) pairs that are independent from other cohorts so that all three requirements could be achieved using ORACLE functions?

In the above scenario, all the records are in one cohort. Either they would go together or not going anywhere.

This is only my thought of resolving the puzzle. If there is any other better idea please let me know.

Thanks a lot!

来源:https://stackoverflow.com/questions/25777460/oracle-sql-split-two-inter-related-lists-into-independent-cohorts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!