表一:TABLE1 KEY  VARCHAR(50)
表二:TABLE2 KEY  VARCHAR(50)描述:
  表一录入4000个KEY,在库中心建一个表TABLE2,输入5000个KEY
  SQL>select count(*) from table1 where key in (select key from table2);
  SQL>4000  SQL>select count(*) from table2;
  SQL>5000
  即表1中的KEY有4000个和表2的KEY一样要求:
   算出表1中存在于表2中的KEY的百分比;
   即select count(a.key)/count(b.key) from table1 a,table2 b;
   麻烦给个语句呢 我怎么算出来是1

解决方案 »

  1.   

    2表没有连接条件,是cross 然后对2个字段进行count ,没有null ,结果是一样的。所以是1
      

  2.   

    select * from(
    select a/lag(a) over(order by 1) m from(
    select count(*) a from ccode c 
    union all
    select count(*) a from askquotefob
    )) where m is not null
      

  3.   

    select count(A.KEY)/count(*) from table1 a,table2 b
    where a.key(+)=b.key
      

  4.   

    select B.sum2/A.sum2 from (select count(*) sum1 from table2),(select count(*) sum2 from table1 where key in(select key from table2)) B;
      

  5.   


    select round(count(a.key)/count(b.key),4)*100||'%' from table1 a right join table2 b on a.key=b.key
      

  6.   

    这样的话,key重复也可以统计。
    SELECT COUNT(DISTINCT a.rowid)/COUNT(DISTINCT b.rowid)  FROM tablea a,TABLEb b
    WHERE b.key=a.key(+)