mysql, count, distinct ;-(

Honza Pazdziora adelton na informatics.muni.cz
Pondělí Červenec 31 12:29:53 CEST 2000


On Sat, Jul 29, 2000 at 11:24:05AM +0200, Robert Vojta wrote:
> Zdravim,
>   presel sem tedka na MySQL a mam treba tabulku:
> 
>   nazev varchar(40) | ip varchar(15)
>   
> 
> COUNT(DISTINCT exprt,[exprt...])
>     Returns a count of the number of different values.
>     mysql> select COUNT(DISTINCT results) FROM student;
> 
>   Tak to zkousim aplikovat na moji tabulku:
> 
>   select count(distinct ip) from tabulka where nazev='neco';
> 
>   a ono to nefunguje, MySQL mi porad rikat, ze mam spatne syntax, ...

Kde? Mate dostatecne nove MySQL?

mysql> select * from hosts ;
+-------+-----------+
| nazev | ip        |
+-------+-----------+
| jezek | 127.0.0.1 |
| krtek | 127.0.0.1 |
| jezek | 127.0.0.2 |
| jezek | 127.0.0.1 |
+-------+-----------+
4 rows in set (0.02 sec)

mysql> select count(distinct ip) from hosts where nazev = 'jezek' ;
+--------------------+
| count(distinct ip) |
+--------------------+
|                  2 |
+--------------------+
1 row in set (0.00 sec)

mysql> select count(ip) from hosts where nazev = 'jezek' ;
+-----------+
| count(ip) |
+-----------+
|         3 |
+-----------+
1 row in set (0.05 sec)

na 3.23.13a.

-- 
------------------------------------------------------------------------
 Honza Pazdziora | adelton na fi.muni.cz | http://www.fi.muni.cz/~adelton/
   .project: Perl, DBI, Oracle, MySQL, auth. WWW servers, MTB, Spain.
Petition for a Software Patent Free Europe http://petition.eurolinux.org
------------------------------------------------------------------------


Další informace o konferenci Test