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 的值时,如何使用group by with left join?
答案 0 :(得分:2)
您需要将GROUP BY更改为
group by org_division.name ,
org_department.name
org_surveylog.division_code,
org_surveylog.department_code
来自Oracle Select Statements : Select Statement With GROUP BY Clause
SELECT <column_name>, <aggregating_operation>
FROM <table_name>
GROUP BY <column_name>;
您会注意到需要在GROUP BY语句中包含非聚合列。