'.'在此位置无效,预期:EOF,';'

'.' is not valid at this position, Expecting : EOF, ';'

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

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, ';'

如有任何帮助,我们将不胜感激。提前致谢

分配table

Id user_department_id entity_id status
1        1              1        1

实体table

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

User_Department table

id, user_id department_id status
1      3         4           1

部门table

id name    cost_code  status
1  finance     011      1

MYSQL-Workbench版本为8.0

您取的密码不是SQL,是Java。

这是 Java 属性:al.userDepartment.department.costCode,您的 SQL 中没有等于 costCode.[=14= 的字段或架构]

Java 代码似乎可以为您自动加入实体。

要在 SQL 中实现同样的效果,您需要 JOIN 喜欢:

SELECT DISTINCT(al.entity)
FROM Allocation al
JOIN User_Department ud
ON a.user_id = al.user_department_id
JOIN Department dep ON al.user_department_id = dep.id
-- ...
WHERE al.status = 1 

试试这个代码:

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 这意味着你只能像这样使用点一次 table_name.column_nametable_alias.column_name