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.

[Oracle 10g] verschachtelte Abfrage

Empfohlene Antworten

Veröffentlicht

Hallo zusammen,

ich möchte gerne aus einer Tabelle mit folgendem Aufbau die Anzahlen jeweils nach Monat ausgegeben haben.

Person | Monat | Anzahl

Es soll dann eine neue Tabelle entstehen die so ausschaut:

Person | Anzahl aktueller Monat | Anzahl voriger Monat | Anzahl vorvoriger Monat

Dabei bin ich wie folgt verfahren:

select person

       , anzahl_0

       , anzahl_1

       , anzahl_2

from (

       select person

              , monat

              , anzahl anzahl_0

       from Tabelle

       where monat= TO_CHAR(SYSDATE,'yyyy-mm')

       order by name

       )

Allerdings weiß ich jetzt nicht, wie ich die anderen beiden Spalten (letzter und vorletzter Monat) befüllen kann. Ich hatte es versucht unter dem zweiten "from" Befehl zu packen, bin aber nicht weitergekommen!

Hat jemand einen Tip?

Vielen Dank!

Der Monat ist als String in der form '2010-07' gespeichert? Ungünstig. Für Datumsangaben nimmt man auch einen entsprechenden Datentyp.

Um die Daten so darzustellen, wie Du es gern hättest benötigst Du Self-joins. Zum Beispiel so:


select  akt.person,

          akt.anzahl as "Anzahl aktueller Monat",

          vor.anzahl as "Anzahl voriger Monat",

          vorvor.anzahl as "Anzahl vorvoriger Monat"

from    Tabelle akt, Tabelle vor, Tabelle vorvor

where  akt.person = vor.person

          and akt.person = vorvor.person

          and akt.monat = TO_CHAR(SYSDATE,'yyyy-mm')

          and vor.monat = add_months( to_date(akt.monat, 'yyyy-mm'), -1 )

          and vorvor.monat = add_months( to_date(akt.monat, 'yyyy-mm'), -2 );

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

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.