COUNT "Grupieren"

DaRula

Erfahrenes Mitglied
Hallo,

ich möchte einen SELECT machen, der mir ausgiebt, wieviel einträge es zu jeweils einem eintrag in einer spalte gibt, also zum Beipsiel des Datums. Damit ich nachsehen kann, wieviele einträge zu jedem Datum vorhanden sind.

Gruß Tobias
 
oh. ein einfache group by löst das problem fast. bei einem timestamp jedoch nciht wirklich. ich möchte dort z.b. alle registrierungen an einem tag. bei dem timestamp handelt es sich um einen unix-timestamp
 
Hallo!

Schau mal hier:
Code:
 mysql> desc t;
 +-------+-----------+------+-----+-------------------+-------+
 | Field | Type	  | Null | Key | Default		   | Extra |
 +-------+-----------+------+-----+-------------------+-------+
 | id	| int(11)   | YES  |	 | NULL			  |	   |
 | time  | timestamp | YES  |	 | CURRENT_TIMESTAMP |	   |
 +-------+-----------+------+-----+-------------------+-------+
 2 rows in set (0.01 sec)
 
 mysql> select * from t;
 +------+---------------------+
 | id   | time				|
 +------+---------------------+
 |	1 | 2005-08-17 15:16:15 |
 |	2 | 2005-08-16 15:16:20 |
 |	3 | 2005-08-16 15:16:23 |
 |	4 | 2005-08-16 15:16:27 |
 |	5 | 2005-08-16 15:16:31 |
 |	6 | 2005-08-15 15:16:37 |
 |	7 | 2005-08-15 15:16:40 |
 +------+---------------------+
 7 rows in set (0.01 sec)
 
 mysql> select id, DATE(time) from t;
 +------+------------+
 | id   | DATE(time) |
 +------+------------+
 |	1 | 2005-08-17 |
 |	2 | 2005-08-16 |
 |	3 | 2005-08-16 |
 |	4 | 2005-08-16 |
 |	5 | 2005-08-16 |
 |	6 | 2005-08-15 |
 |	7 | 2005-08-15 |
 +------+------------+
 7 rows in set (0.02 sec)
 
 mysql> select count(id), DATE(time) registration_date from t group by registration_date;
 +-----------+-------------------+
 | count(id) | registration_date |
 +-----------+-------------------+
 |		 2 | 2005-08-15		|
 |		 4 | 2005-08-16		|
 |		 1 | 2005-08-17		|
 +-----------+-------------------+
 3 rows in set (0.03 sec)

Gruß Tom
 

Neue Beiträge

Zurück