我正在尝试按错误类型进行分组,但不断收到此错误。 列'fid_crm_sp_recon.URL'在选择列表中无效,因为它不包含在聚合函数或GROUP BY子句中。
SELECT URL, Name, statusCode, ErrorType
FROM fid_crm_sp_recon
GROUP BY ErrorType
答案 0 :(得分: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;
答案 1 :(得分:0)
group by应始终与select
子句后的聚合函数一起使用,或者将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