Benutzer-Werkzeuge

Webseiten-Werkzeuge


notiz:nuetliches-sql

Nützliches SQL

doppelter join

Wir hätten gerne aus einer Tabelle nur die Zeile wo climate.date max ist, gruppiert nach climate.stations und wollen noch stations.name anzeigen.

SELECT stations.lat AS lat, stations.lon AS lon, stations.name AS name, climate.tmk AS tmk
FROM climate
INNER JOIN (
    SELECT climate.station, MAX(climate.date) AS DATE
    FROM climate
    GROUP BY climate.station
) AS c
ON climate.station = c.station AND climate.date = c.date
INNER JOIN stations
ON climate.station = stations.id
ORDER BY climate.station;
notiz/nuetliches-sql.txt · Zuletzt geändert: 2020/04/29 22:27 von clerie

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki