首页 > 解决方案 > '。' 在这个位置无效,期望:EOF,';'

问题描述

我不确定mysql语句有什么问题。我正在尝试运行以下查询,该查询是从我的项目中的 Eclipse 中的存储库类中获取的。

select distinct(al.entity) from Allocation al where al.status = 1 and  al.userDepartment.user is not null 
and al.userDepartment.department.costCode in ('finance')
and al.entity.locationFloor.id = 1 ;

它向我显示错误.costCode以及.id'.' is not valid at this position, Expecting : EOF, ';'

任何帮助,将不胜感激。提前致谢

分配表

Id user_department_id entity_id status
1        1              1        1

实体表

id, entity_type_id, entity_child_type_id, location_floor_id, status
1        1                1                     1               1

User_Department 表

id, user_id department_id status
1      3         4           1

部门表

id name    cost_code  status
1  finance     011      1

MYSQL-Workbench 版本为 8.0

标签: mysqlmysql-workbench

解决方案


试试这个代码:

select distinct al.entity 
(from (Allocation al join User_Department ud on al.user_department_id = ud.department_id ) 
join Department D on d.id = al.user_department_id )
join Entity E on al.entity_id = E.id 
where al.status = 1 
and  ud.user_id is not null 
and d.name in ('finance')
and E.location_floor_id = 1 ;

而不是使用点使用join,因为点用于获取特定表的列,这意味着您只能像这样使用点一次table_name.column_nametable_alias.column_name


推荐阅读