Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hi,

ich habe mal wieder ein kleines Problemchen mit einer SQL-Abfrage und meine Frage ist, wie ich das am Besten löschen könnte.

Verwende dabei folgende Abfrage:

SELECT DISTINCT a.c_industry "Industry", a.c_market_segment "Market Segment", a.c_application "Application", a.c_oq_code "OQ_Code", c.net_dom_amount "Amount (Local Currency)"

FROM IFSAPP.c_oq_code a

LEFT JOIN IFSAPP.customer_order b ON a.c_oq_code = b.c_oq_code

LEFT JOIN IFSAPP.customer_order_inv_head c ON b.order_no = c.creators_reference

WHERE c.contract = ('&Site')

AND c.invoice_date BETWEEN TO_DATE('&From_Date', 'DD-MM-YYYY') AND TO_DATE('&To_Date', 'DD-MM-YYYY')

GROUP BY (a.c_industry, a.c_market_segment, a.c_application, a.c_oq_code, c.net_dom_amount)

Das Ergebnis:

sql1.png

Wunderbar soweit, jedoch möchte ich die Summe für die Spalte "Amount (Local Currency)" abbilden können, nur hab ich damit so meine Probleme. Befehl SUM, keine Ahnung wie ich das am Idealsten löse. GROUP BY ROLLUP gäbe es auch, jedoch klappt das nicht sehr gut...

Aussehen sollte es dann so:

sql2.png

Alle Spalten können gern leer sein, bis auf die Spalte "Amount (Local Currency)", in der ja der Summe der 6 oberen Zahlen drin stehen sollte.

Jetzt bräuchte ich eure Ideen, wie ich das am sinnvollsten Umsetzen könnte.

Falls jemand fragen hat, bin ich gerne dazu bereit sie zu beantworten.

Vielen Dank!

Grüße

iceQ7

Auf Anhieb würde ich das über ein UNION lösen. Die letzte Zeile verlangt einen anderen Query:


SELECT DISTINCT a.c_industry "Industry", a.c_market_segment "Market Segment", a.c_application "Application", a.c_oq_code "OQ_Code", c.net_dom_amount "Amount (Local Currency)"[B][U], 0[/U][/B]

FROM IFSAPP.c_oq_code a

LEFT JOIN IFSAPP.customer_order b ON a.c_oq_code = b.c_oq_code

LEFT JOIN IFSAPP.customer_order_inv_head c ON b.order_no = c.creators_reference

WHERE c.contract = ('&Site')

AND c.invoice_date BETWEEN TO_DATE('&From_Date', 'DD-MM-YYYY') AND TO_DATE('&To_Date', 'DD-MM-YYYY')

GROUP BY (a.c_industry, a.c_market_segment, a.c_application, a.c_oq_code, c.net_dom_amount)


[B][U]UNION[/U][/B]


SELECT "leer","leer","leer", 0, 0[B][U], SUM(c.net_dom_amount) "Summe"[/B][/U]

FROM IFSAPP.c_oq_code a

LEFT JOIN IFSAPP.customer_order b ON a.c_oq_code = b.c_oq_code

LEFT JOIN IFSAPP.customer_order_inv_head c ON b.order_no = c.creators_reference

WHERE c.contract = ('&Site')

AND c.invoice_date BETWEEN TO_DATE('&From_Date', 'DD-MM-YYYY') AND TO_DATE('&To_Date', 'DD-MM-YYYY')

GROUP BY (a.c_industry, a.c_market_segment, a.c_application, a.c_oq_code, c.net_dom_amount)


Ich bin mir nicht sicher, ob es so funktioniert, aber probier es mal aus.

Das fette unterstrichene habe ich hinzugefügt.

Vielleicht fällt jemandem ja noch eine bessere Lösung ein.

Gruß

Hallo Genodi,

vielen Dank erst einmal für deine Hilfe. Deine Methode bringt zu einem das gewünschte Ergebnis, jedoch ist der Wert falsch...

Genau so stell ich es mir vor, jedoch ist die Summe verkehrt. Rechne ich die Spalte in Excel zusammen, ergibt das einen Unterschied.

Gibt es eine Möglichkeit per ROLLUP?

Gruß

iceQ7

jetzt müsste ich passen, haber derzeit noch nie mit Rollup gearbeitet sorry.

Aber wenn das Ergebnis nicht passen sollte, dann kann es nur am JOIN oder an der WHERE klausel liegen oder nicht?

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.