怎么用sql算出两个表中数量的百分比
有两张表a表和b表怎么从a表中查出来学生总数和b表中的学生总数并求出来两个表的学生总数的百分比?...
有两张表a表和b表 怎么从a表中查出来学生总数和b表中的学生总数并求出来两个表的学生总数的百分比
? 展开
? 展开
3个回答
展开全部
with t1 as (select count(*) f from a), t2 as (select count(*) f from b)
select (select f*1. from a)/((select f from a)+(select f from b))
select (select f*1. from a)/((select f from a)+(select f from b))
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select
f1/(f1+f2)*100.00,
f2/(f1+f2)*100.00
from
(select (select count(*) from t1) as f1,(select count(*) from t2) as f2 ) as t_t
f1/(f1+f2)*100.00,
f2/(f1+f2)*100.00
from
(select (select count(*) from t1) as f1,(select count(*) from t2) as f2 ) as t_t
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
;with t
as
(
select count(聚集索引所在字段) as total from a
union all
select count(聚集索引所在字段) from b
)
select sum(total ) as total from t
union all
select total /sum(total )*1.0 as 百分比 from t group by total
as
(
select count(聚集索引所在字段) as total from a
union all
select count(聚集索引所在字段) from b
)
select sum(total ) as total from t
union all
select total /sum(total )*1.0 as 百分比 from t group by total
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询