我有一个表X,它有一个名为version的列,其中有4-5个值。示例1、2、3、4、5
如果列值是1或3,那么我就是好的,否则就是and错误
问题
查询是什么,所以我想要这样的输出
值的总数|总好即值为(1,3) |总失败即值不在(1,3)中
有没有人能帮我解决这个问题
发布于 2012-05-12 03:52:31
您可以尝试这样做:
select count(*) as TotalValues
, (select count(*) from test where id in(1, 3)) as TotalGood
, (select count(*) from test where id not in (1, 3)) as TotalFailed
from test
SQL Fiddle DEMO
根据您的评论,如果您需要百分比,您将使用以下内容:
SELECT TotalValues
, TotalGood
, TotalFailed
, Cast(TotalGood as decimal(10, 2))/Cast(TotalValues as decimal(10, 2)) as PercentGood
FROM
(
select count(*) as TotalValues
, (select count(*) from test where id in(1, 3)) as TotalGood
, (select count(*) from test where id not in (1, 3)) as TotalFailed
from test
) x
https://stackoverflow.com/questions/10557670
复制相似问题