SQL查询出的值怎么相加

2024-11-25 10:56:13
推荐回答(5个)
回答1:

--有两闭前散个方法

--楼下的是一种 tmp是表的别名
--两外一种就是 把条件合在一起就轿氏可以了 前提是二者没有交叉
select count(1) from KJ_XMJB
where ((fXMCGXS>0 and fXMCGXS<5) or fXMCGXS=8) or

(fXMJSJJMB>0 AND fXMJSJJMB<3)
--不明白可以随时问我 希望悔游采纳

回答2:

将两个值竖罩分别付给两个变量。乱纤蠢将第一个count(*)改为count(1),第二个改为count(2),
count(1)哗陪+count(2)即可

回答3:

试并悄试这样:闷蔽誉

select sum(a) from
(
SELECT count(*) a from KJ_XMJB where (fXMCGXS>0 and fXMCGXS<蚂段5) or fXMCGXS=8
union all
SELECT count(*) a from KJ_XMJB where fXMJSJJMB>0 AND fXMJSJJMB<3
) tmp

回答4:

select count(*) from (
SELECT * from KJ_XMJB where (fXMCGXS>0 and fXMCGXS<5) or fXMCGXS=8

union all
SELECT * from KJ_XMJB where fXMJSJJMB>缺咐芹伏毕简败0 AND fXMJSJJMB<3)

回答5:

SELECT count(*)from KJ_XMJB where (fXMCGXS>皮姿侍0 and fXMCGXS<册棚5) or fXMCGXS=8
or fXMJSJJMB>燃吵0 AND fXMJSJJMB<3