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.

Problem mit SQL Abfrage

Empfohlene Antworten

Hallo,

ich habe ein Problem mit einer SQL Abfrage. Ich habe folgende Tabelle:

Artikel | Umsatz | Monat

4711 | 50,25 | 01

9857 | 147,58 | 01

4711 | 78,55 | 02

9857 | 29,73 | 02

4711 | 47,58 | 03

9857 | 125,25 | 03

4711 | 48,22 | 04

9857 | 15,50 | 04

4711 | 123,58 | 05

9857 |582,20 | 05

4711 | 8,55 | 06

9857 | 2,73 | 06

4711 | 47,11 | 07

9857 | 14,25 | 07

4711 | 99,98 | 08

9857 | 107,20 | 08

4711 | 66,88 | 09

9857 | 123,44 | 09

4711 | 44,44 | 10

9857 | 22,73 | 10

4711 | 47,22 | 11

9857 | 125,25 | 11

4711 | 55,58 | 12

9857 | 845,33 | 12

Ich muss jetzt eine Abfrage erstellen mit der ich herausfinden kann was für ein Umsatz die Artikel 4711 und 9857 in den einzelne Quartale und das gesamt Jahr gebracht haben. So müsste also das Ergebnis aussehen:

Artikel | Umsatz Gesamt | 1 Quartal | 2 Quartal | 3 Quartal | 4 Quartal

4711 | 784,82 | 176,38 | 180,35 | 213,97 | 214,12

Das Ergebnis muss für alle Artikel angezeigt werden.

Wie kann ich das mit einer SQL Abfrage hinbekommen??

Gruß

netfireman

Hmm, denk, denk, überleg ...

select artikel, sum(umsatz) from tab where artikel IN (4711,9857) group by artikel
So das liefert dir die ersten zwei Werte ... *schnell nen Kaffee hol* Jetzt bin ich vollkommen verwirrt :confused: Subselect in dem Select statement ... geht das ?? Bei Oracle schon ... Also:
select artikel, sum(umsatz), 

(select sum(umsatz) from tabelle where monat IN (1,2,3) and artikel = 4711), 

(select sum(umsatz) ...)

[...]

from tabelle

group by ...

Nicht getestet ... aber diese Richtung muesste stimmen ...

/edit: Habe das Gefühl, dass ich viel zu kompleziert denke ... . Welche DB benutzt du eigentlich ?

ich benutze de MS SQL Server 2000

Ich werde es gleich einmal ausprobieren.

Ich weiß jetzt wie es geht. Und zwar so:

Select artikel,Quartal1 = SUM(CASE WHEN Monat between(1,2,3) THEN Umsatz END), Quartal2 = SUM(CASE WHEN Monat between(4,5,6) THEN Umsatz END)

Form tab

group by ...

Gruß

netfireman

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Konto

Navigation

Suchen

Suchen

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.