用户未使用 group by 按单位分组

users are not grouped by units using group by

我使用 postgres 作为数据库

我想按单位显示员工

我尝试使用此查询,但结果员工未按单位分组

select employee_lang.fullname_emp_lang,unit_lang.name_unit_lang

from employee employee,employee_lang employee_lang,unit unit,unit_lang unit_lang
where  employee.id_employe= employee_lang.id_employe
and employee_lang.lang_emp_lang='ar'
and employee.id_unit= unit.id_unit
and unit.id_unit= unit_lang.id_unit
and unit_lang.lang_unit_lang='ar'
group by employee_lang.fullname_emp_lang,unit_lang.name_unit_lang

比如我想要这样的结果

alen     dep1
franc    dep1
med      dep1
juk      dep2
sizar    dep2

我也尝试使用

分组 unit_lang.name_unit_lang

意思是

 select employee_lang.fullname_emp_lang,unit_lang.name_unit_lang

    from employee employee,employee_lang employee_lang,unit unit,unit_lang unit_lang
    where  employee.id_employe= employee_lang.id_employe
    and employee_lang.lang_emp_lang='ar'
    and employee.id_unit= unit.id_unit
    and unit.id_unit= unit_lang.id_unit
    and unit_lang.lang_unit_lang='ar'
    group by unit_lang.name_unit_lang

我有这个错误:

ERROR: column "employee_lang.fullname_emp_lang" must appear in the GROUP BY clause or be used in an aggregate function

我觉得你是求订单,不是求分组:

select employee_lang.fullname_emp_lang,unit_lang.name_unit_lang    
from employee employee,employee_lang employee_lang,unit unit,unit_lang unit_lang
where  employee.id_employe= employee_lang.id_employe
and employee_lang.lang_emp_lang='ar'
and employee.id_unit= unit.id_unit
and unit.id_unit= unit_lang.id_unit
and unit_lang.lang_unit_lang='ar'
order by unit_lang.name_unit_lang