MySQL Forums
Forum List  »  German

UNION oder wie das alles zusammen passt
Posted by: Sebastian Olisch
Date: April 07, 2009 03:56AM

Hallo allerseits,

ich wollte gerade zum ersten mal in meinem Leben UNION benutzen, weil mir der Befehl laut der MySQL Doku recht sinnvoll erschien. Aber das Ergebnis ist irgendwie anders als ich erwartet habe. Denn ich dachte, der Befehl fasst automatisch etwas zusammen. Mein Ergebnis sieht ungefähr so aus:
area_reputation	quests_in_area	rqaid	area_name
7695		34		65	Drachenöde
3055		15		67	Die Sturmgipfel
985		9		210	Eiskrone
4335		19		394	Grizzlyhügel
500		1		1497	Unterstadt
10		1		1637	Ogrimmar
9020		49		3537	Boreanische Tundra
420		4		65	Drachenöde
10		1		3537	Boreanische Tundra
Das Ziel von mir war es aber eigentlich, dass doppelte Einträge "zusammengefasst" werden. Also ich hatte gehofft, dass im Ergebnis "9030, 50, 3537, Boreanische Tundra" statt "9020, 49, 3537, Boreanische Tundra" und "10, 1, 3537, Boreanische Tundra" steht. Gibt es eine Möglichkeit das noch mal mit GROUP oder sowas zusammen zu fassen? Oder muss ich das nachher in PHP weiterbearbeiten?

Mein MySQL String dazu sieht ungefähr so aus:

(SELECT SUM( reputation ) AS area_reputation, COUNT( wow_quests.id ) AS quests_in_area, wow_zones.id AS rqaid, wow_zones.name AS area_name
FROM wow_quests, wow_zones
WHERE wow_quests.instance_id = wow_zones.id
AND wow_quests.type =1 AND wow_quests.faction_id =1085
GROUP BY wow_quests.instance_id
ORDER BY wow_quests.instance_id
) UNION (
SELECT SUM( wow_questreputation.reputation ) AS area_reputation, COUNT( wow_questreputation.quest_id ) AS quests_in_area, wow_zones.id AS rqaid, wow_zones.name AS area_name
FROM wow_quests, wow_questreputation, wow_zones
WHERE wow_quests.instance_id = wow_zones.id
AND wow_questreputation.faction_id =1085 AND wow_quests.type =1
AND wow_questreputation.quest_id = wow_quests.id
GROUP BY wow_quests.instance_id
ORDER BY wow_quests.instance_id)



Edited 1 time(s). Last edit at 04/07/2009 04:02AM by Sebastian Olisch.

Options: ReplyQuote


Subject
Views
Written By
Posted
UNION oder wie das alles zusammen passt
7999
April 07, 2009 03:56AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.