这是自连接么?
都是使用sql server自带的pubs数据库,
1.use pubs
select title,type,advance
from titles t1
where t1.advance >(select avg(t2.advance) from titles t2
where t1.type=t2.type)
结果集为7
2.select title,type,advance
from titles t1
where t1.advance >(select avg(t2.advance) from titles t2
) 结果集为8
偶也以为:
前者的意思:
查出 按type分类,advance 大于本类平均值的记录
后者的意思:
查出 advance 大于全部平均值的记录
可是
[前者的意思:
查出 按type分类,advance 大于本类平均值的记录]
这样的话,是否说每个type分类都要返回一条平均值的值,所以总体应该有多个返回值,为何下面的语句只有一条返回值呢:?
select avg(t2.advance) from titles t2, titles t1
where t1.type=t2.type |