Ich habe eine Viele-zu-Viele Beziehung und ich möchte alle W's und ihre Summe (Häufigkeit) für einige A's finden, die zu einem bestimmten Datum erstellt wurden. Was ist der beste Weg, dies zu tun?Wie finden Sie die Summe in einem Viele-zu-Viele für bestimmte Bedingungen?
sollte das Ergebnis nicht:
w.name | sum
-------+------
bar | 2
bar | 5
baz | 4
bim | 3
foo | 2
foo | 3
Das Ergebnis sollte sein:
w.name | sum
-------+------
bar | 7
baz | 4
bim | 3
foo | 5
Meine Tabellen:
Tabelle A:
id | title | author | created_at
----+-------+--------+-------------
... | ... | ... | ...
11 | abc | ccc | Thu, 5 Apr 2012 08:01:25 GMT
12 | bcb | ddd | Thu, 5 Apr 2012 10:11:15 GMT
13 | dfg | aaa | Fri, 6 Apr 2012 07:33:45 GMT
Tabelle AW:
id | aid | wid | freq
----+-----+-----+------
... | ... | ... | ...
201 | 11 | 2 | 2
202 | 11 | 3 | 4
203 | 11 | 17 | 2
204 | 12 | 17 | 3
205 | 12 | 66 | 1
206 | 12 | 12 | 2
207 | 12 | 24 | 5
208 | 12 | 7 | 3
209 | 13 | 2 | 5
210 | 13 | ... | ...
Tabelle W:
id | name | ...
----+-------+--------
... | ... | ...
2 | bar | ...
3 | baz | ...
... | ... | ...
7 | bim | ...
... | ... | ...
17 | foo |
Gruppe durch Anweisung fehlt – dash1e