Registriert seit: 23. Jan 2008
3.686 Beiträge
Delphi 2007 Enterprise
|
Re: [SQL] JOIN joint zu oft
14. Jan 2010, 14:48
AHHHH! Genial!
SQL-Code:
SELECT
Rez_Name,
Text,
Anz,
SUM(Menge) AS Menge
FROM (
SELECT
k.REZ_NAME AS REZ_NAME,
k.KOMMENT AS TEXT,
COUNT(p.CHARGE)*1.0 AS Anz,
ROUND(SUM(p.ANTEIL_I))*1.0 AS Menge
FROM
rpohis p JOIN rkohis k ON p.REZ_NR = k.REZ_NR AND p.V_Dat = k.V_Dat AND k.Charge = p.Charge
WHERE
p.Rez_Nr = 1
GROUP BY
k.REZ_NAME, p.Komp_Nr
ORDER BY
k.REZ_NAME) AS tmp
GROUP BY
Rez_Name
Daaaaaas funktionieeeert! Ich danke euch ganz ganz kräftig!
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
|