一种方法是将表与自身连接:
select count(*) as TotalCount, count(s.id) as QualifiedCountfrom MyTable aleft join MyTable s on s.id = a.id and {some conditions}
另一种方法是使用子查询:
select (select count(*) from Mytable) as TotalCount, (select count(*) from Mytable where {some conditions}) as QualifiedCount
select count(*) as TotalCount, sum(case when {some conditions} then 1 else 0 end) as QualifiedCountfrom MyTable
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)