select
[总数量] = count(a.id),
[有效数量] = sum(case b.result when '成功' then 1 else 0 end)
from
table a
inner join
table b
on
a.id = b.id
[总数量] = count(a.id),
[有效数量] = sum(case b.result when '成功' then 1 else 0 end)
from
table a
inner join
table b
on
a.id = b.id
[总数量] = count(*),
[有效数量] = sum(case result when '成功' then 1 else 0 end)
from
[table]
sum(case when b.result='成功' then 1 else 0 end) as '有效数量'
from table a inner join table b on a.id = b.id