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 distinct Aggregatsfunktion

Empfohlene Antworten

Veröffentlicht

Hallo Forum,

ich habe folgende Tabelle:


iid / IBAno / iba_date / done ...

iid ist primary key und autocount. IBAno ist Integer und kann gleiche Werte enthalten. Nun möchte ich mit einem SQL Befehl alle Datensätze auslesen, wobei er aber alle weglässt die bei IBAno den gleichen Wert stehen haben. Mit folgendem Befehl geht es leider nicht:
select distinct iid, IBAno, iba_date, done from ta_iba

Kann mir irgendjemand helfen?

Danke und Gruß

Druid :cool:

Die Lösung ist folgendes SQL Statement:

select distinctrow IBAno, iba_date, done from ta_iba

iid darf man nicht mit rein nehmen, da sonst das distinct logischerweise

keine Wirkung mehr hat.

Greetz

Druid :cool:

oder auch


select iid, IBAno, iba_date, done from ta_iba group by IBAno

Gruß,

Markus

Der Vollständigkeit wegen:

select distinct IBAno, iba_date, iid, done from ta_iba;

... ohne das "row" hinter distinct. Und mit "iid" falls du die Spalte auch brauchst.

DISTINCT heißt so viel wie "einmalig", du musst es vor den Spaltennamen schreiben, dessen Werte du als einmalige Version haben möchtest. Wenn du es vor dem Primary Key schreibst kriegst du natürlich alle Datensätze zurück, da ja jeder Wert in der Spalt IID einmalig ist.

GROUP BY hat meines Wissens nach nur eine Funktion, wenn man im Select-Teil auch eine Gruppenfunktion (max, count, min,...) anwendet. Ansonsten dürfte es mMn sogar Fehler geben (beim Ansprechen eines GROUP BY ohne Gruppenfunktion).

ORDER BY hingegen sortiert deine Ausgabe nach einer Spalte, ORDER BY IBAno sortiert deine Ausgabe nach den Werten in IBAno. Eine aufwärtssortiere Ausgabe ist dabei default.

[edit] das hat mich doch interessiert: group by geht doch ohne Gruppenfunktion... meine Güte... man erlebt noch Zeiten und wunder![/edit]

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.