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.

[SQL] Abfrage mit Join und Count in zweiter Tabelle

Empfohlene Antworten

Veröffentlicht

Hallo zusammen,

leider weiß ich nicht, wo ich Fragen bezüglich SQL Statements posten soll, darum mein Versuch hier:

Ich habe 2 Tabellen:

[table=width: 500, class: grid]

[tr]

[td]ID[/td]

[td]Titel[/td]

[/tr]

[tr]

[td]1[/td]

[td]Testtitel1[/td]

[/tr]

[tr]

[td]2[/td]

[td]Testtitel2[/td]

[/tr]

[/table]

[table=width: 500, class: grid]

[tr]

[td]ID1[/td]

[td]ID2[/td]

[/tr]

[tr]

[td]1[/td]

[td]1[/td]

[/tr]

[tr]

[td]1[/td]

[td]2[/td]

[/tr]

[/table]

Jetzt möchte ich sowohl den Titel als auch die Anzahl der Vorkommnisse aus der zweiten Tabelle auslesen. Das Ergebnis sollte also so aussehen:

[table=width: 500, class: grid]

[tr]

[td]Titel[/td]

[td]Anzahl[/td]

[/tr]

[tr]

[td]Testtitel[/td]

[td]2[/td]

[/tr]

[tr]

[td]Testtitel2[/td]

[td]0[/td]

[/tr]

[/table]

Irgendwie bekomme ich das aber garnicht auf die Reihe. Ich habe die Vermutung, dass ich mit LEFT JOIN, GROUP BY und HAVING arbeiten muss, aber dann hört es leider auch schon auf. Wenn mir da jemand helfen könnte wäre das super.

Vielen Dank schonmal!

Hallo

versuchs mal mit:

SELECT d.Title,

case when tmp.cnt is null then 0 else tmp.cnt end

FROM [Tabelle1] as d

  left join ( select Id1, Count(Id1) as cnt from Tabelle2 group By Id1) as tmp on tmp.Id1=d.Id

Das wäre eine mögliche Lösung.

Gruß

Jogibaer0411

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.