I think this is an interesting question. Note the following:

count(col1) will tell you the number of non-null occurrences of col1
col1=value will return 1 is col1=value, 0 if col1<>value
1/0 will return null

thus,

count(1/(col1=value)) will tell you the number of occurences of value in
col1.

therefore, if you have three conditions on col1: value1, value2, value3, you
can run:

select count(1/(col1=value1)) C1, count(1/(col1=value2)) C2,
        count(1/(col1=value3)) C3
from table where col1 in (value1,value2,value3);

does this help?

braxton

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Cindy
Sent: Thursday, April 26, 2001 4:02 PM
To: [EMAIL PROTECTED]
Subject: count(*) questions



OK, I have a perl script using mysql that pulls up a bunch of numbers
for a table.  Problem is it's taking a long time because of the number of
select calls I'm making.

Basically, I have a sequence of calls of the form:

SELECT COUNT(*) FROM <table> WHERE <conditions>
(execute, get value of count, print out as cell item in table)

for each column in the row.

My question:  Is there some way to consolidate all the calls in each
row into one select statment? Ie,

SELECT COUNT(*), COUNT(*), COUNT(*) FROM <table> WHERE <conditions#1>
<cond#2> <cond#3>

Then I'd do one call per row for a total of row queries, rather
than for rowXcolumns queries.

I'm thinking I might be able to do this with some form of aliasing,
but I'm kind of stumped on how to specify which set of conditions goes
to which count.



--Cindy
--
[EMAIL PROTECTED]

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail
<[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to