我是SQL的新手并尝试一起构建6个表的连接。这是我的示例代码:
SELECT cr.COMMUNICATIONS_ID, cr.CONSUMER_ID, cr.ACTION_LOG_ID, nc.CONSUMER_ID, cal.CONSUMER_ID, cal.TIPS_AMOUNT, cal.LAST_MOD_TIME, cirm.CONSUMER_RATING, ces.EXPERT_SCORE, cim.CONSUMER_INTEREST_EXPERT_ID, scs.SIMILARITY
FROM COMMUNICATION_RELVANCE AS cr
JOIN network_communications AS nc
ON cr.COMMUNICATIONS_ID=nc.COMMUNICATIONS_ID
JOIN consumer_action_log AS cal
ON cr.ACTION_LOG_ID=cal.ACTION_LOG_ID
JOIN communication_interest_mapping AS cim
ON cr.COMMUNICATIONS_ID=cim.COMMUNICATIONS_ID
JOIN consumer_interest_rating_mapping AS cirm
ON cr.CONSUMER_ID=cirm.CONSUMER_ID
AND cim.CONSUMER_INTEREST_EXPERT_ID=cirm.CONSUMER_INTEREST_ID
JOIN consumer_expert_score AS ces
ON nc.CONSUMER_ID=ces.CONSUMER_ID
AND cim.CONSUMER_INTEREST_EXPERT_ID=CONSUMER_EXPERT_ID
JOIN survey_customer_similarity AS scs
ON nc.CONSUMER_ID=scs.CONSUMER_ID
AND cal.CONSUMER_ID=scs.CONSUMER_ID;
在开始调试之前,我想确保我的代码中没有任何批发问题我的语法。
答案 0 :(得分:5)
这对我来说很好看。尝试运行它以查看是否有任何错误。
有几点:
COMMUNICATION_RELVANCE
。你可能应该在编写太多代码之前解决这个问题。我知道这听起来很迂腐,但这是因为在初始开发过程中修复它可能很容易。如果你留下太长时间,人们会编写依赖于拼写错误的代码,最终可能会因更改名称和更新所有现有代码而变得太困难/昂贵。然后你就会被它困住,这将使每个必须在未来几年内维护你的代码的人感到烦恼。答案 1 :(得分:0)
所有行看起来都很好,除非您可能希望在此行中添加别名,而CONSUMER_EXPERT_ID
为“正确”
AND cim.CONSUMER_INTEREST_EXPERT_ID=CONSUMER_EXPERT_ID