Felix Geerinckx wrote:
On 28/11/2005, Gobi wrote:
I need to write a select clause based on the following conditions:
If all rows of status1 == "Neg"
count all "Neg" rows in status1
else
check if all rows of status2 == "Neg"
count all "Neg" rows in status2 and status1
endif
endif
Not sure if I understand this completely. Does the following give what
you want?
SELECT
CASE
WHEN MAX(status1) = MIN(status1) AND status1 = 'Neg' THEN
SUM(IF(status1 = 'Neg', 1, 0))
WHEN MAX(status2) = MIN(status2) AND status2 = 'Neg' THEN
SUM(IF(status1 = 'Neg', 1, 0) +
IF(status2 = 'Neg', 1, 0))
ELSE NULL
END AS count
FROM foo;
Not exactly but thanks for trying. I currently have a filter which
works on one column:
select count(*) from dummy where status1 = 'Neg'
and not exists (select 1 from dummy where status1 = 'Pos');
The above query filters out ALL the rows if even one row containing
'Pos' or 'Ind' exists. Now, what I want to do is to extend this query
so that it searches status1 first. If the above query on status1 fails
(that is one row of 'Pos' or 'Ind' exists), then I have to check
status2. If all the rows in status2 = "Neg" then I can count the "Neg"
rows in column1. On the other hand, if the condition succeeds then only
rows with status1 = "Neg" is counted.
Hope that clarifies my problem.
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]