表一:tab1
字段:id,name,sex...
表二:tab2
字段:id,name,sex...
要求:用一条sql查询出表一中name为 “xx”的人数占表二中name为 “xx” 的人数的百分比
(select count(id) from tab1 where name="xx")/(select count(id) from tab2 where name="xx")
这样好像不行啊
------解决方案--------------------------------------------------------
怎么不行?
select count(id)/(select count(id) from tab2 where name="xx")
from tab1 where name="xx"
------解决方案--------------------------------------------------------
select (select count(id) from tab1 where name="xx")/(select count(id) from tab2 where name="xx")