0

我正在尝试按 errorType 分组,但不断收到此错误。列 'fid_crm_sp_recon.URL' 在选择列表中无效,因为它不包含在聚合函数或 GROUP BY 子句中。

SELECT URL, Name, statusCode, ErrorType
FROM fid_crm_sp_recon
GROUP BY ErrorType
4

2 回答 2

1

如评论中所述,您根本没有group by正确设置。这里有几种可能让您走上正确的道路:

-- Group by all columns
SELECT URL, Name, statusCode, ErrorType
FROM fid_crm_sp_recon
GROUP BY URL, Name, statusCode, ErrorType;

-- Run aggregates on the non-grouped columns
SELECT MIN(URL) AS MinURL
    , MAX(Name) AS MaxName
    , AVG(statusCode) AS AvgStatusCode -- Assuming a number here, just an example
    , ErrorType
    , COUNT(*) AS Num
FROM fid_crm_sp_recon
GROUP BY ErrorType;
于 2013-06-14T18:22:49.980 回答
0

group by 应始终与聚合函数 afterselect子句一起使用或将 group by 应用于所有选定的列

 SELECT URL, Name, statusCode, ErrorType  FROM fid_crm_sp_recon  GROUP BY URL, Name, statusCode, ErrorType

你可以通过这些链接

http://www.techonthenet.com/sql/group_by.php http://www.w3schools.com/sql/sql_groupby.asp

于 2013-06-14T18:35:38.653 回答