Organize database & multichoice columns by cronjob

别等时光非礼了梦想. 提交于 2020-01-05 01:31:28

问题


seller:
  id, age, origin, gender, buyer_age, buyer_origin, buyer_gender

buyer:
  id, age, origin, seller_age, seller_origin, seller_gender

Here we want to suggest the buyer to buy from this seller
AND
suggest the seller to sell things to the buyer
with cronjob.
Doing it with one query is preferred instead of foreach seller. What's the most efficient way to do it? I don't want to SELECT each one and get info then change the query and again SELECT that's a killing process in coding and using system memory. If there's a possibility of using join or so with below statement then it's OK.
If seller or buyer says age and origin is NOT important for me, then how is it possible? Is there

 WHERE seller_origin = ANY

in mysql?


回答1:


Firstly change all the column names in both buyer and seller to be prefixed with the name of the table in which they originate as we will be joining tables.

SELECT *
FROM seller       
INNER JOIN buyer
ON
        (seller.buyer_gender = buyer.gender OR seller.buyer_gender IS NULL) AND
        (buyer.seller_gender = buyer.gender OR buyer.seller_gender IS NULL) AND
        (seller.buyer_origin = buyer.origin OR seller.buyer_origin IS NULL) AND
        (buyer.seller_origin = seller.origin OR buyer.seller_origin IS NULL) AND
        (seller.buyer_age = buyer.age OR seller.buyer_age IS NULL) AND
        (buyer.seller_age = seller.age OR buyer.seller_age IS NULL)  


来源:https://stackoverflow.com/questions/31214144/organize-database-multichoice-columns-by-cronjob

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