【发布时间】:2012-11-07 14:58:22
【问题描述】:
我有一个带有几个相同表的 mySQL 数据库。每次id1 和id2 在至少 2 个表中相等时,我需要加入所有表并总结视图和点击,如果不是,则简单地显示该行。
请看下表结构:
Table1:
id..id2...views...hits
1...102...55......12
2...103...12......22
Table2:
id..id2...views...hits
1...123...512......13
2...103...123......43
Table3:
id..id2...views...hits
1...102...232......43
2...103...100......70
最终结果应该如下表:
id...id2...views...hits
1....102...287....65 <-- This one is the result of adding 1st row of table1 and 2nd row of table 2
1....123...512....13 <-- This is the 1st row of table2 as there's no other id2 = 123
2....103...235....135 <-- This is the sum of 2nd row in table1 + 2nd row in table2 + 2nd row in table3
我希望这是有道理的,有人可以提供帮助。
谢谢!
【问题讨论】: