1

失败语句:错误:ORA-00979:不是 GROUP BY 表达式

 select org_division.name  , org_department.name , org_surveylog.division_code as divisionCode,org_surveylog.department_code as departmentCode , max(org_surveylog.actiondate) from org_surveylog 
left join org_division on (org_surveylog.division_code= org_division.division_code and org_surveylog.SURVEY_NUM= org_division.survey_num)
left join org_department on (org_surveylog.department_code = org_department.department_code and org_surveylog.SURVEY_NUM = org_department.survey_num) 
 group by org_surveylog.division_code,org_surveylog.department_code 

但下面没问题

 select org_surveylog.division_code as divisionCode,org_surveylog.department_code as departmentCode , max(org_surveylog.actiondate) from org_surveylog 
left join org_division on (org_surveylog.division_code= org_division.division_code and org_surveylog.SURVEY_NUM= org_division.survey_num)
left join org_department on (org_surveylog.department_code = org_department.department_code and org_surveylog.SURVEY_NUM = org_department.survey_num) 
 group by org_surveylog.division_code,org_surveylog.department_code 

当我需要显示org_division.name , org_department.name的值时,如何使用左连接 分组 ?

4

1 回答 1

2

您需要将 GROUP BY 更改为

 group by   org_division.name , 
            org_department.name
            org_surveylog.division_code,
            org_surveylog.department_code 

Oracle 选择语句:使用 GROUP BY 子句选择语句

SELECT <column_name>, <aggregating_operation>
FROM <table_name>
GROUP BY <column_name>;

您会注意到您需要在 GROUP BY 语句中包含非聚合列。

于 2010-04-14T03:47:08.193 回答