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 Statement Where Bedingung Größterwert

Empfohlene Antworten

Veröffentlicht

Hi zusammen,

ich bin auf der suche nach einer lösung für folgendes Problem

Spalten der Tabelle

ID vernr Wert

Die Daten sehen z.B. so aus

1,1,1

1,2,2

1,3,1

2,1,10

...

100,1,2007

usw.

Der Primärschlüßel setzt sich also aus der ID und der Vernr zusammen.

Ich möchte nun ein select bauen das mir folgendes ergebniss ausspuckt

1,3,1

2,1,10

100,1,2007

also Pro ID nur einen datensatz und zwar den mit der größten vernr

geht das? Ich habe es schon mit Max in der where bedingung versucht aber das funktioniert wohl nicht

achja ist eine MSSQL DB

schon mal thx

Grüße

Wolf

Da kommst Du um eine Unterabfrage nicht drum rum. Versuch mal folgendes:



Select * From TabelleA ta

Inner Join 

   (Select ID, max(vernr) as max_vernr  From TabelleA Group By ID) as ta_max

       On ta.ID = ta_max.ID And ta.vernr = ta_max.max_vernr 

Bilde zuerst eine Unterabfrage mit id, max(versionsnummer) über alle Datensätze und Joine diese Abfrage mit der Ursprungstabelle

oder

SELECT ... FROM ... WHERE (id, vernummer) IN (SELECT id, max(versionsnummer) FROM ...)

vom Gefühl her dürfte das erste schneller sein

alles klar thx leute ich hatte gehoft ich könnte um die unzterabfrage rum kommen da in der tb ca. 2 mio. datensätze sind

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.