MySQL Forums
Forum List  »  German

Re: Komplizierte Abfrage...
Posted by: Harald Bacik
Date: August 10, 2012 10:40AM

Hallo
Leicht umgebaut, kommt das der Sache schon näher:

SELECT u.article, u.powera, u.powerb, anzahl
FROM (SELECT a.article,
p.powera_re AS PowerA, p.powerB_re AS PowerB,
COUNT(*) AS anzahl
FROM article a
JOIN POWER p
ON a.powerid = p.id
WHERE a.type = 1
GROUP BY PowerA, PowerB

UNION

SELECT a.article,
p.powera_li AS PowerA, p.powerB_li AS PowerB,
COUNT(*) AS anzahl
FROM article a
JOIN POWER p
ON a.powerid = p.id
WHERE a.type = 2
GROUP BY PowerA, PowerB

) u;

Ergibt:

article powera powerb anzahl
Article B -3.00 \N 1
Article A -2.00 \N 1
Article A -2.00 -0.75 1
Article A -1.00 \N 1

Was vom Grundschema schon passt, nur die Anzahl mit immer 1 stimmt leider nicht...

Options: ReplyQuote


Subject
Views
Written By
Posted
1877
July 24, 2012 04:57AM
1156
August 06, 2012 10:50AM
1153
August 09, 2012 03:00AM
1150
August 09, 2012 03:51AM
1066
August 10, 2012 08:22AM
1109
August 10, 2012 10:19AM
1161
August 10, 2012 10:30AM
Re: Komplizierte Abfrage...
1153
August 10, 2012 10:40AM
1111
August 10, 2012 11:13AM
1029
August 10, 2012 11:17AM


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.