本文发表在 rolia.net 枫下论坛my work result in sql server.
select * from employee
empname depname empsalary
-------------------- -------------------- --------------------
Mike A 1000
Tom A 1100
Jame A 1800
Peter A 2000
Bob B 1900
Alice B 2200
Ben B 1000
Joe B 1300
(8 row(s) affected)
select * from employee t1 where t1.empsalary >
(select avg(empsalary) from employee t2 where t2.depname = t1.depname )
empname depname empsalary
-------------------- -------------------- --------------------
Jame A 1800
Peter A 2000
Bob B 1900
Alice B 2200
(4 row(s) affected)更多精彩文章及讨论,请光临枫下论坛 rolia.net
select * from employee
empname depname empsalary
-------------------- -------------------- --------------------
Mike A 1000
Tom A 1100
Jame A 1800
Peter A 2000
Bob B 1900
Alice B 2200
Ben B 1000
Joe B 1300
(8 row(s) affected)
select * from employee t1 where t1.empsalary >
(select avg(empsalary) from employee t2 where t2.depname = t1.depname )
empname depname empsalary
-------------------- -------------------- --------------------
Jame A 1800
Peter A 2000
Bob B 1900
Alice B 2200
(4 row(s) affected)更多精彩文章及讨论,请光临枫下论坛 rolia.net