Ja, im Statement oben ist ein Copy&Paste Fehler drin.
(round(sum(ap.ap_preis * sod.sod_menge), 2).
Schon klar, erst lesen dann posten. Hat aber keine Auswirkung auf das Problem.
1.)
das mt dem View in MySql vergiss erstmal dafür finde ich ne Lösung.
Das hier ist wichtiger!
2.)
Im Anhang ist ein Dump mit den Beispieltabellen. Der Vollständigkeit halber sind da alle Tabellen drin.
3.)
Ich habe das Problem auf das 'CASE' eingekreist.
Ich habe da keine Aggregationen drin und müsste auch so funktionieren,
HTML-Code:
<PRE>
SELECT
sod_sotid,
CASE
WHEN (a.a_einheit= 3 AND a.a_refgewicht> 0) THEN
a.a_refgewicht * sod.sod_menge
ELSE
sod.sod_menge
END AS sod_gpreis
FROM sortdetail sod
LEFT JOIN artikel a ON a.a_id = sod.sod_artid
WHERE sod.sod_sotid =2
GROUP BY sod_sotid
ORDER BY sod.sod_soid
</PRE> Aber da bekomme ich folgenden Error:
column "a.a_einheit" must appear in the GROUP BY clause or be used in an aggregate function...
Damit dieses Statement ausgeführt wird muss ich ALLE Spalten in die
Group by Klausel aufnehmen sogar sod.sod_soid die nur in der ORDER BY steht 
HTML-Code:
<PRE>
GROUP BY sod_sotid,a.a_einheit,a.a_refgewicht,sod.sod_menge,sod.sod_soid
</PRE>
Achtung: Nicht verwechseln sod_soid & sod_sotid
Das Ergebnis ist nicht das was ich will ich will (in dem kleinen Beispiel) nur nach sod_soid gruppieren!
Irgendeine Idee?
Lesezeichen