select count(*) from tab1 inner join (select id from tab2 where months_between(sysdate,tab2.birthday)/12>65)e on tab1.id=e.id;
select count(*) from tab1 eah inner join tab2 on tab1.id=tab2.id where months_between(sysdate,tab2.birthday)/12>65;
select count(*) from tab1 where EXISTS (select 1 from tab2 where tab1.id=tab2.id and months_between(sysdate,tab2.birthday)/12>65 );
------解决方案-------------------- SELECT COUNT(1)-- COUNT(*)个人习惯是count(1)或者具体的count(fieldName) FROM tab1 INNER JOIN (SELECT id FROM tab2 WHERE months_between(sysdate,tab2.birthday)>65*12 --比较符左边尽量不使用计算 --WHERE months_between(sysdate,tab2.birthday)/12>65 )e ON tab1.id=e.id;
------解决方案--------------------