please try the whole comment, statement in () can inherit those alias like "t1"defined outside, I guess you are a new guy, and havn't got the sql sever here, but I do, and try the statement already. Trust me.

tuantuan (团团)
本文发表在 rolia.net/zh 相约加拿大网上社区枫下论坛
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/zh
(#28841@0)
2001-2-26 -05:00

回到话题: help! SQL assignment due tomorrow...

回到论坛: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论

URL:   
http://www.rolia.net/zh/post.php?f=0&p=28841