List:General Discussion« Previous MessageNext Message »
From:Jan Dvorak Date:August 21 2000 4:45pm
Subject:Re: Is there a way to...
View as plain text  
Hi,

X-Odus wrote:
> 
> Get counts that mean different expressions?
> like :
>   SELECT COUNT(WHERE user LIKE '10.10.%'), COUNT(user) from entry_log;
> 
> anyone know? or do I have to do multiple queries?

There is a way:

select
   sum( if( user like '10.10.%', 1, 0 ) ) as cnt_users_like_10_10,
   count( user ) as cnt_all_nonnull_users
 from
   entry_log;

The downside is that MySQL will do this in a table scan.
I.e., you should also try your two-query variant 
and see which one performs better.

> --Don

Jan
Thread
Is there a way to...X-Odus21 Aug
  • Re: Is there a way to...Jan Dvorak21 Aug