Problem mit MSSQL Abfrage
Hallo, ich habe folgendes Problem:
Tabelle mit folgenden Spalten
ICD, ICDTXT, DiagArt, Anzahl
A46 , Unterschenkel, 20, 2
A46 , Unterschenken, 10, 1
DiagArt 10 = Hauptdiagnose, 20 = Nebendiagnose
Ich möchte jetzt eine Auswertung die wie folgt aussieht
ICD , ICDTXT , Haupt , Neben
A46 , Unterschenkel , 1 , 2
Kann mir da jemand Helfen?
Danke schonmal
Andreas
Tabelle mit folgenden Spalten
ICD, ICDTXT, DiagArt, Anzahl
A46 , Unterschenkel, 20, 2
A46 , Unterschenken, 10, 1
DiagArt 10 = Hauptdiagnose, 20 = Nebendiagnose
Ich möchte jetzt eine Auswertung die wie folgt aussieht
ICD , ICDTXT , Haupt , Neben
A46 , Unterschenkel , 1 , 2
Kann mir da jemand Helfen?
Danke schonmal
Andreas
Please also mark the comments that contributed to the solution of the article
Content-Key: 124538
Url: https://administrator.de/contentid/124538
Printed on: April 26, 2024 at 04:04 o'clock
2 Comments
Latest comment
SELECT a.`ICD`, a.`ICDTXT`, h.`Haupt`, n.`Neben`
FROM
? a
LEFT JOIN (SELECT `ICD`, SUM(`Anzahl`) AS 'Haupt' FROM ? WHERE `DiagArt` = 10 GROUP BY `ICD`) h ON a.`ICD` = h.`ICD`
LEFT JOIN (SELECT `ICD`, SUM(`Anzahl`) AS 'Neben' FROM ? WHERE `DiagArt` = 20 GROUP BY `ICD`) n ON a.`ICD` = n.`ICD`
ORDER BY
// ...
;