Group by in mysql
Fred
- datenbank
Hallo
Datenbank mySQL 5.1.41
Ich habe folgende Tabelle:
TestNr PCB-Nr Datum
1 00000 2011-06-07 10:17:10
2 00514 2011-06-07 10:26:05
3 00000 2011-06-07 11:08:04
4 00000 2011-06-07 11:09:13
5 00000 2011-06-07 11:09:15
6 20017 2011-06-09 13:37:35
7 20017 2011-06-09 14:14:10
8 20017 2011-06-10 08:10:58
9 20017 2011-06-10 08:27:12
10 20017 2011-06-10 09:38:01
11 20017 2011-06-10 09:46:11
und brauche
* Jeweils den neuste Datensatz einer PCB-Nr.
* Auch sollen die Datensätze noch nach Datum sortiert sein.
* Anzahl gleicher PCB-Nr. (das ist Kür)
TestNr PCB-Nr Datum Anzahl gleicher PCB-Nr.
11 20017 2011-06-10 09:46:11 6
5 00000 2011-06-07 11:09:15 4
2 00514 2011-06-07 10:26:05 1
Abfrage bis jetzt, habe ich diese Abfrage:
SELECT TestNr, ArtikelNr, PlatinenNr, Datum, count(PlatinenNr)
FROM Tabelle
GROUP BY PlatinenNr
ORDER BY Datum DESC
Hat jemand eine Idee, ob das überhaupt geht?
Gruß
Fred
Hallo Fred,
Ich habe folgende Tabelle:
TestNr PCB-Nr Datum
1 00000 2011-06-07 10:17:10
2 00514 2011-06-07 10:26:05
3 00000 2011-06-07 11:08:04
4 00000 2011-06-07 11:09:13
5 00000 2011-06-07 11:09:15
6 20017 2011-06-09 13:37:35
7 20017 2011-06-09 14:14:10
8 20017 2011-06-10 08:10:58
9 20017 2011-06-10 08:27:12
10 20017 2011-06-10 09:38:01
11 20017 2011-06-10 09:46:11
* Jeweils den neuste Datensatz einer PCB-Nr.
* Auch sollen die Datensätze noch nach Datum sortiert sein.
* Anzahl gleicher PCB-Nr. (das ist Kür)
TestNr PCB-Nr Datum Anzahl gleicher PCB-Nr.
11 20017 2011-06-10 09:46:11 6
5 00000 2011-06-07 11:09:15 4
2 00514 2011-06-07 10:26:05 1
Hat jemand eine Idee, ob das überhaupt geht?
ja, nur nicht mit GROUP BY, sondern mit Subselects, siehe Archiv.
Freundliche Grüße
Vinzenz