Thread Probleme mit GROUP BY (7 answers)
Opened by format_c at 2007-01-17 11:20

format_c
 2007-01-17 11:20
#35101 #35101
User since
2003-08-04
1706 Artikel
HausmeisterIn
[Homepage] [default_avatar]
Hi ich hab folgendes Szenario

meine Tabelle dev hat folgenden inhalt
Code: (dl )
1
2
3
4
5
6
7
8
+---------+----------------+
| dev_idx | dev_ip_addr |
+---------+----------------+
| 40 | 192.168.52.252 |
| 709 | 192.168.24.62 |
| 708 | 192.168.24.61 |
| 615 | 192.168.24.60 |
+---------+----------------+


meine Tabelle ping_times folgenden
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
+--------+--------+---------------------+
| dev_id | rtime | ptime |
+--------+--------+---------------------+
| 40 | 10.001 | 0000-00-00 00:00:00 |
| 40 | 10.001 | 2007-01-17 00:00:00 |
| 40 | 10.001 | 0000-00-00 00:00:00 |
| 40 | 10.001 | 2007-01-17 08:56:40 |
| 40 | 4.012 | 2007-01-17 08:58:07 |
| 615 | 5.245 | 2007-01-17 09:30:54 |
| 615 | 10.245 | 2007-01-17 09:34:12 |
+--------+--------+---------------------+


Jetzt möchte ich alle Geräte der Tabelle dev angezeigt bekommen und die jeweils höchsten Zeiteinträge der Tabelle ping_times die die selbe dev_id haben. Ich habe das mit folgendem Kommano versucht
[sql]SELECT
dev.dev_idx,dev.dev_ip_addr,
times.rtime,times.ptime,MAX(times.ptime)
FROM DEV AS dev
LEFT JOIN DEV_PING_TIMES AS times
ON
dev.dev_idx =times.dev_id
GROUP BY
dev.dev_idx
;

[/sql]

Was ich jedoch bekomme ist:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
+---------+----------------+--------+---------------------+---------------------+
| dev_idx | dev_ip_addr | rtime | ptime | MAX(times.ptime) |
+---------+----------------+--------+---------------------+---------------------+
| 40 | 192.168.52.252 | 10.001 | 0000-00-00 00:00:00 | 2007-01-17 08:58:07 |
| 221 | 192.168.24.43 | NULL | NULL | NULL |
| 222 | 192.168.24.2 | NULL | NULL | NULL |
| 223 | 192.168.24.3 | NULL | NULL | NULL |
| 224 | 192.168.24.4 | NULL | NULL | NULL |
| 225 | 192.168.24.5 | NULL | NULL | NULL |
| 227 | 192.168.24.8 | NULL | NULL | NULL |
| 228 | 192.168.24.15 | NULL | NULL | NULL |
| 615 | 192.168.24.60 | 5.245 | 2007-01-17 09:30:54 | 2007-01-17 09:34:12 |
| 708 | 192.168.24.61 | NULL | NULL | NULL |
| 709 | 192.168.24.62 | NULL | NULL | NULL |
+---------+----------------+--------+---------------------+---------------------+


Kann mir jemand helfen?

Gruß Alex

View full thread Probleme mit GROUP BY