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;
--
felix
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]