tricky count operation in the middle of a join |
10/20/2009 11:59:40 AM |
PHPRunner General questions | |
![]() I have two tables, WorkshopMaster and WorkshopDetail. On the Master List Page I'd like to count the number of COUPLES for each workshop. SELECT
SELECT Count(*) AS Couples FROM `WorkshopDetail` WHERE `Male's Name` IS NOT NULL AND `Female's Name` IS NOT NULL
|
|
K
|
KevinMillican 10/20/2009 |
I have two tables, WorkshopMaster and WorkshopDetail. On the Master List Page I'd like to count the number of COUPLES for each workshop. These workshops are mostly for married couples, but sometimes only one of the couple can show up. Each record in the WorkshopDetail has a field for Male's Name and Female's Name. When only one of the couple shows up, we just enter that info in the approriate field, leaving the other name field blank. I figured out how to add a field in PHPRunner on the Query tab for the Count() for both these fields. Like this: SELECT
SELECT Count(*) AS Couples FROM `WorkshopDetail` WHERE `Male's Name` IS NOT NULL AND `Female's Name` IS NOT NULL
|
![]() |
phray author 10/21/2009 |
Try (WorkshopDetail. Male's Name > "") * (WorkshopDetail.Female's Name > "") AS Couple,in your query, and get the total of the Couple virtual field instead.
(WorkshopDetail.`Male's Name` > "") AS Males
|
K
|
KevinMillican 10/21/2009 |
Interesting, but I'm not sure how to interpret the results I'm getting. These are text fields that are submitted as NULL when they're blank so the COUNT() comes out right. When I do (WorkshopDetail.`Male's Name` > "") AS Males
|
![]() |
phray author 10/21/2009 |
The value will be a 1 if both fields, are filled, or zero otherwise. You can change its properties to display a tick to indicate a couple, and if you tell PHPrunner to summarise that column as a Total, it will show you the number of couples.
|