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.

Count in Oracle; Sql

Empfohlene Antworten

Hallo zusammen,

ich habe ein kleines Problem. Ich möchte mir daten aus einer Oracle-Tabelle lesen, in der:

1. Bestimmte einträge aus "Spalte1" liest. (geht)

2. Bestimmte einträge aus "Spalte2" liest. (geht)

3. Einen Count auf bestimmte einträge aus den Spalten 3 und diese jeweils zuordnet.

Die Tabelle sieht so aus

spalte1 spalte2 spalte3

AAA 111 J

AAA 222 N

AAA 222 J

AAA 222 J

BBB 222 N

BBB 333 N

BBB 222 N

BBB 333 J

CCC 111 N

CCC 333 N

CCC 111 J

CCC 222 N

also es sind alle kombinationsmöglichkeiten erlaubt

die ausgabe der Daten (von oben sollte nun so aussehn)

Spalte1 | Spalte2 | J | N

AAA 111 1 0

AAA 222 2 1

BBB 222 0 2

BBB 333 1 1

CCC 111 1 1

CCC 222 0 1

CCC 333 0 1

Ist für euch mein Problem plausibel? Ich mache einen select auf die Tabelle und dann ein group by auf spalte1, spalte2. Jedoch weiß ich nicht, wie ich es hinbekomme die Zählerspalten (j/n) so zu füllen, dass es pro zeile die jeweilige anzahl aus Spalte1 und Spalte2 zählt.

Danke schon mal für eure Hilfe

Gruß

Uli

Moin,

mal so aus der hohlen Hand und wie immer ungetestet:


select spalte1, spalte2

, sum(case when spalte3 = 'J' then 1 else 0 end) as J

, sum(case when spalte3 = 'N' then 1 else 0 end) as N

from tabelle

group by spalte1, spalte2 

ich nehme an, dass das unter Oracle8 nicht funktioniert, ab Oracle9 sollte das im Prinzip aber klappen.

Reinhold

Dankeschön.... hat sich erledigt, es geht so... falls nochmal jemand das gleiche problem hat:


select a.spalte1, a.spalte2,

(select count(*) 

from tabelle b 

where b.spalte2 = a.spalte2 

and b.spalte1= a.spalte1 

and spalte3 = 'J') 

as JA, 

(select count(*) 

from tabelle b 

where b.spalte2 = a.spalte2 

and b.spalte1= a.spalte1 

and spalte3 = 'N') 

as NEIN

from tabelle a 

group by spalte2, spalte1

hätte ich nicht gedacht dass es so geht... *Asche auf mein Haupt* :upps

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.