当前位置: 代码迷 >> 其他数据库 >> SQL语句
  详细解决方案

SQL语句

热度:10048   发布时间:2013-02-26 00:00:00.0
SQL语句求助!
表一: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")
  相关解决方案