いくつかの同一のテーブルを持つmySQLデータベースがあります。すべてのテーブルを結合し、少なくとも2つのテーブルでid1
とが等しいたびにビューとヒットを合計するか、そうでない場合は単に行を表示する必要があります。id2
以下の表の構造を参照してください。
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
これが理にかなっていて、誰かがそれを手伝ってくれることを願っています。
ありがとう !