SELECT COUNT(C1)+COUNT(C2)+COUNT(C3)+COUNT(C4) AS 总数 FROM TB WHERE C1='TRUE'OR C2='TRUE'OR C3='TRUE'OR C4='TRUE'不知道行不??!!
select distinct ((select count(*) as true from TB where c1='true')+ (select count(*) as true from TB where c2='true')+ (select count(*) as true from TB where c3='true')+ (select count(*) as true from TB where c4='true')) as true, ((select count(*) as true from TB where c1='false')+ (select count(*) as true from TB where c2='false')+ (select count(*) as true from TB where c3='false')+ (select count(*) as true from TB where c4='false')) as false from TB 这样就可以了,TRUE和false出现的次数都可以统计出来
上面那个条件这样加不对,改下!CREATE TABLE TB(C1 VARCHAR(10),C2 VARCHAR(10),C3 VARCHAR(10),C4 VARCHAR(10)) INSERT TB VALUES('TRUE','TRUE','FALSE','TRUE')SELECT SUM(总数)总数 FROM (SELECT COUNT(C1)总数 FROM TB WHERE C1='TRUE' UNION ALL SELECT COUNT(C2)总数 FROM TB WHERE C2='TRUE' UNION ALL SELECT COUNT(C3)总数 FROM TB WHERE C3='TRUE' UNION ALL SELECT COUNT(C4)总数 FROM TB WHERE C4='TRUE') AS T总数 ----------- 3(所影响的行数为 1 行)
SELECT COUNT (CASE WHEN CO1=TRUE THEN 1 WHEN COL2=TRUE THEN .....) FROM XX
WHERE C1='TRUE'OR C2='TRUE'OR C3='TRUE'OR C4='TRUE'不知道行不??!!
(select count(*) as true from TB where c2='true')+
(select count(*) as true from TB where c3='true')+
(select count(*) as true from TB where c4='true')) as true,
((select count(*) as true from TB where c1='false')+
(select count(*) as true from TB where c2='false')+
(select count(*) as true from TB where c3='false')+
(select count(*) as true from TB where c4='false')) as false
from TB
这样就可以了,TRUE和false出现的次数都可以统计出来
INSERT TB VALUES('TRUE','TRUE','FALSE','TRUE')SELECT SUM(总数)总数
FROM
(SELECT COUNT(C1)总数 FROM TB WHERE C1='TRUE'
UNION ALL
SELECT COUNT(C2)总数 FROM TB WHERE C2='TRUE'
UNION ALL
SELECT COUNT(C3)总数 FROM TB WHERE C3='TRUE'
UNION ALL
SELECT COUNT(C4)总数 FROM TB WHERE C4='TRUE') AS T总数
-----------
3(所影响的行数为 1 行)