Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 以下哪项是有效的查询?_Mysql_Sql_Database_Database Schema - Fatal编程技术网

Mysql 以下哪项是有效的查询?

Mysql 以下哪项是有效的查询?,mysql,sql,database,database-schema,Mysql,Sql,Database,Database Schema,我对聚合函数和select语句中允许的内容有些混淆。所以我有一张小纸条: Restrictions on aggregation: if any aggregation is used, then each element in the select list must be either aggregated or an attribute on the group by list 我对上述内容的困惑是:这是否意味着select语句中作为聚合函数参数的任何内容都必须分组?即 select

我对聚合函数和select语句中允许的内容有些混淆。所以我有一张小纸条:

Restrictions on aggregation: if any aggregation is used, then each element 
in the select list must be either aggregated or an attribute on the group by list 
我对上述内容的困惑是:这是否意味着select语句中作为聚合函数参数的任何内容都必须分组?即

select max(attribute) from table group by attribute 
我不理解对聚合的限制

这就引出了我的问题:

这是我的模式:我不知道如何画下划线,所以我只说明键

Student(sID, surName, firstName, campus, email, cgpa) key: sID
Course(dept, cNum, name, breadth)   key: dept, cNum
Offering(oID, dept, cNum, term, instructor)   key: oID
Took(sID, oID, grade)  key: sID, oID
我有一个未完成的sql查询:

select ________ from Offering, Took where Offering.oID = Took.oID group by dept
以下哪项可以包含在select子句中?为什么允许

sid,    count(sid),  grade,  avg(grade),  dept,  count(dept),  term,  min(term)

编辑:编写了错误的查询。现在它是正确的。抱歉。

使用聚合时,
SELECT
子句中不在聚合函数中的任何字段也应该在
GROUP BY
中,否则您不能在
SELECT
中使用该字段


在您的示例中,这些字段必须按
分组:sid、年级、部门、术语

@这是用于新查询的吗?或者你以前看到的那个?你能提供你想要得到的数据样本和预期结果吗?这将有助于lot@Alex这就基本上回答了这个问题,不是吗pAssuming仅适用于一列,则上述所有列均不适用。正确答案是dept加上任何(和/或所有)聚合列。好吧,你可以。MySQL原谅了这种做法——但这是一种不好的做法。