Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.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
Sql server 2012 如何对SQL server中的多个列使用GROUP BY_Sql Server 2012 - Fatal编程技术网

Sql server 2012 如何对SQL server中的多个列使用GROUP BY

Sql server 2012 如何对SQL server中的多个列使用GROUP BY,sql-server-2012,Sql Server 2012,我正在从事现有的项目,该项目是在Laravel+Mysql上开发的。现在,我已经将我的数据库从Mysql迁移到Sql server。所以所有在project中使用Mysql语法编写的查询 现在,我有一个问题如下: SELECT table_1.*, table_3.date as sem1date FROM table_1, table_2, table_3 WHERE table_3.ID=table_2.DID AND block_datelu.BID=table_1.final_exa

我正在从事现有的项目,该项目是在Laravel+Mysql上开发的。现在,我已经将我的数据库从Mysql迁移到Sql server。所以所有在project中使用Mysql语法编写的查询

现在,我有一个问题如下:

SELECT table_1.*, table_3.date as sem1date 
FROM table_1, table_2, table_3 
WHERE table_3.ID=table_2.DID AND block_datelu.BID=table_1.final_exam_date AND table_1.centreid=1234 AND table_1.course=1 
GROUP BY table_1.start_date, table_1.end_date  
当我将上述查询转换为sql server语法时,sql server向我发出错误消息“列“table_1.Id”在选择列表中无效,因为它不包含在聚合函数或GROUP BY子句中。


有人能告诉我如何对具有联接的多个列使用group by吗?

最好使用现代的explizit join而不是implizit join。您只能选择group by子句中的值或聚合值。因此,在您的案例中
选择表1.start\u date、表1.end\u date、max(表3.date)作为sem1date…