This topic is locked

Problem with count(*) function in Charts

8/31/2007 10:37:48 PM
PHPRunner General questions
H
Halo author

Hi, I am currently evaluating phpRunner and am having a problem with Charts.
I have a data similar to this one and am using a similar select statement:
SELECT species, sex, COUNT() FROM pet GROUP BY species, sex;

+---------+------+----------+

| species | sex | COUNT(
) |

+---------+------+----------+

| bird | NULL | 1 |

| bird | f | 1 |

| cat | f | 1 |

| cat | m | 1 |

| dog | f | 1 |

| dog | m | 2 |

| hamster | f | 1 |

| snake | m | 1 |
what I expect to be able to do in charts is generate a chart with Species as a label, then as my data series, I should have access to : the number of females, number of males and number of nulls for each species.

From that I should be able to create a stacked chart (like the 2d stacked column) with Species along the bottom. and a stack (numbered above each species showing totals for each sex associated with same species.

But instead, I get only count(*) as a data series choice, and I can pick either sex or species as my label. The resulting chart is meaningless as it contains :

Bird: total 1

Bird: total 1

Cat: total 1 etc, but no way to tell what it is a total of (that it is e.g. total 1 female).

It is as though the grouped sub-totals are not recognised.
I'm new to this, just checking if the product meets our needs, so apologies for the long question. Am I doing something silly (I hope so!), or is this a bug/serious limitation?
All help and advice much appreciated.

Brilliant product, by the way!
Version 4.0 (build 265) Evaluation

Sergey Kornilov admin 9/1/2007

You need to modify your SQL query so it returns something like this:
+---------+------+----------------+

| species | male | female | null |

+---------+------+----------------+

| bird | 0 | 1 | 1

| cat | 1 | 1 | 0
etc
You can only use numeric fields as a data series.

H
Halo author 9/1/2007

Thanks Sergei,
I know this is not a phprunner query but a SQL query then... and I'm no expert. The best I can come up with is:
SELECT species,

(SELECT count() FROM animaltable where Sex = 'Male') AS 'Male',

(SELECT count(
) FROM animaltable where Sex = 'Female' ) AS 'Female'

from animaltable GROUP BY species
Which genrates the following incorrect output: (the values for bird are appearing for every animal)
species | male | female |

+---------+------+-----+

| bird | 0 | 1 |

| cat | 0 | 1 |

| dog | 0 | 1 |
Is there a SQl expert out there who can help me to fix my query..?

Sergey Kornilov admin 9/2/2007

Halo,
send your database to support@xlinesoft.com. I'll try to figure something out.

H
Halo author 9/4/2007

Thanks Sergey,

I 've sent you some data.

Alexey admin 9/4/2007

Halo,
here is the query that should work:

SELECT species,

sum(case when sex='m' then 1 else 0 end) as male,

sum(case when sex='f' then 1 else 0 end) as female

FROM pet GROUP BY species

H
Halo author 9/4/2007

Alexey, Sergey
What can I say..? I have only 3 comments:

1 - This works, perfect chart output, exactly as I wanted!

2 - You guys rock!!

3 - I'm so happy with the product and especially the support - I've just bought a licence!!!
Thanks so much for your help!

Halo (another happy customer)