如何得出SQL SERVER 2005 两个表各自行数的比值?
比如:表A有11行,表B有22行,如何select 出(表A行数与表B行数的比值)?
其中:表A与表B有相同列,可以join。
追问:select (select * from dbo.v_Genpact_Systems)/(select * from dbo.v_Genpact_TodayLastLogon)
报错:
Msg 116, Level 16, State 1, Line 2
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
Msg 116, Level 16, State 1, Line 2
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.每个表都加一个where条件,那又是什么格式呢?谢谢。
答案:select (select count(*) from 表A)/(select count(*) from 表B)
这样就可以实现的.
不过要注意分母别为0哦~
看是否合适吧
其他:select count(a.*)/count(b.*) as 比值 from A a,B b; select sum(rc1)/sum(rc2) from (select count(*) as rc1,0 as rc2 from A union select 0 as rc1,count(*) as rc2 from B) t
上一个:SQL密码设置为空,用友却显示由于SQL server的超级用户口令修改过,用友网络财务软件不能连接
下一个:目前电脑上装的是sql server 2000,请问若要使用pl/sql,以实现while循环,是否需要安装新的软件?谢谢!