现在有两张表,要查每个部门里个人薪资大于部门平均薪资的人的所有信息。
SELECT c.id,c.name,c.bum,d.age,c.time,c.se,d.xinz
from t2 c
LEFT JOIN (
SELECT a.sid,a.xinz,a.sex,a.age
from t1 a
LEFT JOIN (SELECT sex,avg(xinz) as xinz FROM t1 GROUP BY sex) b
on a.xinz>b.xinz and a.sex=b.sex
WHERE b.xinz!='Null') d
on c.id=d.sid
where d.xinz!="Null"