主题:一条让人郁闷的语句查询
supergood
[专家分:0] 发布于 2006-06-03 12:36:00
在表a中
sno cno degree
103 245 86
105 245 75
109 245 68
108 166 81
107 166 75
101 166 79
. . .
. . .
. . .
.
. . .
要求检索起成绩(degree)比该课程(cno)平均成绩高的表记录
如:
cno为24时 avg(degree)=76.3
则检索出了 sno103 cno245 degree86 这一条记录
回复列表 (共4个回复)
沙发
wangsdong [专家分:21390] 发布于 2006-06-03 12:46:00
select * from a where degree>(select avg(cno) from a)
板凳
supergood [专家分:0] 发布于 2006-06-03 15:49:00
楼上的,不行啊
3 楼
a97191 [专家分:4040] 发布于 2006-06-05 17:55:00
declare @t table(sno int,cno int,degree int)
insert @t select 103, 245, 86
union all select 105, 245, 75
union all select 109, 245, 68
union all select 108, 166, 81
union all select 107, 166, 75
union all select 101, 166, 79
select *from @t a,(select cno,avg(degree) as degree from @t group by cno)b where a.degree>b.degree and a.cno=b.cno
4 楼
古都青鸟 [专家分:60] 发布于 2006-06-06 22:40:00
假定你要搜索课程cno245的记录
select * from a where degree > (select avg(degree) from a where cno = 245)
我来回复