注册 登录
编程论坛 SQL Server论坛

【求助】这是哪儿错了,求关于两个参量的均值的最大值,并且要能知道对应哪个参数

咖啡色裂变 发布于 2013-12-02 17:19, 524 次点击
select MAX(dd) from (select AP,AVG(data) as 'dd',lb  from test group by AP,lb) temp group by LB
这句话可以通过,但是当变一下
select ap,MAX(dd) from (select AP,AVG(data) as 'dd',lb  from test group by AP,lb) temp group by LB
然后就出错了,
消息 8120,级别 16,状态 1,第 1 行
选择列表中的列 'temp.AP' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中

这是为什么?


[ 本帖最后由 咖啡色裂变 于 2013-12-2 17:41 编辑 ]
3 回复
#2
volte2013-12-04 13:33
可以先把group by 语法和聚合函数语法学习一下,再写这个程序;
#3
落泪的鱼72013-12-12 22:31
select ap,max(dd) from temp
where dd in(select AP,AVG(data) as 'dd',lb  from test group by AP,lb)
group by LB;  ----应该可以吧!
#4
落泪的鱼72013-12-12 22:31
select ap,max(dd) from temp
where dd in(select AP,AVG(data) as 'dd',lb  from test group by AP,lb)
group by LB;  ----应该可以吧!
1