我有4个表有一个得分列(10分最高的分数)如何使用其他三个表中列的平均值更新一个表中的分数列?
这种结构类似于一个我在我的真正的数据库:
- master_entity(id, name, **score**, other-columns...)
- scores_table1(id, score_giver1_id, master_entity_id, **score**)
- scores_table2(id, score_giver2_id, master_entity_id, **score**)
- scores_table3(id, score_giver3_id, master_entity_id, **score**)
我想执行一个简单SQL脚本(用于MySQL数据库)每天都有一个cron作业。该脚本必须使用其他三个表中的分数列的平均值更新master_entity.score列。
但从得分列在scores_table1平均仅代表1/6平均得分列价值在master_entity。
另外,从得分柱在scores_table2平均必须表示只是平均得分列值的2/6在master_entity最后从得分柱在scores_table3平均绝仅代表3/6的平均值得分栏值master_entity
什么是推荐的SQL更新master_entity.score列使用其他3个表中分数的比例平均值?
写公式下来,你会得到一半查询。把它的连接和条件放在另一半上。 – axiac 2015-02-05 23:33:47