Mysql '';在此位置无效,应为:EOF,'';
我不确定mysql语句有什么问题。我正试图从我的项目中运行下面的查询,该查询来自eclipse中的Repository类Mysql '';在此位置无效,应为:EOF,'';,mysql,mysql-workbench,Mysql,Mysql Workbench,我不确定mysql语句有什么问题。我正试图从我的项目中运行下面的查询,该查询来自eclipse中的Repository类 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.locationFlo
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
上显示错误,表示'.'在此位置无效,应为: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
用户/部门表
id, user_id department_id status
1 3 4 1
id name cost_code status
1 finance 011 1
部门表
id, user_id department_id status
1 3 4 1
id name cost_code status
1 finance 011 1
MYSQL工作台版本是8.0您使用的代码不是SQL,而是Java
这是一个Java属性:al.userDepartment.department.costCode
,SQL中没有等于costCode
的字段或模式
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\u name.column\u name
或table\u alias.column\u name
这些点来自何处al.userDepartment.department.costCode
在我看来无效