select count(*) as "所查人数" from (select * from table_a a, table_b b where a.pid = b.pid) t where t.name like '张%' and t.age >= 24 and t.age <= 50; select avg(t1.age) as "所查平均年龄" from (select * from table_a a, table_b b where a.pid = b.pid) t1 where t1.name like '张%' and t1.sex = '男';