mysql - '。' 在这个位置无效,期望: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
解决方案
试试这个代码:
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_name
或table_alias.column_name
推荐阅读
- javascript - 如何在本地开发过程中使生产环境无法访问 Firebase?
- flutter - 使用 Mocktail 和 Cubits 进行小部件测试
- python - 我如何在 django rest framework api 中生成 qr 代码
- php - 使用 PHP 计算不同的价格排列
- python - 使用长短期记忆 (LSTM) 和 Keras 加入意图预测和槽填充
- java - 由于 intellij 中的 'io/soabase/recordbuilder/processor/RecordBuilderProcessord,无法加载处理器类文件
- php - 无法从 Walmart API 获取商品
- html - For 属性可以与 HTML 表单中的 name 属性连接吗?
- javascript - 找出哪个正则表达式与 JavaScript 中的给定字符串匹配
- python - 在kivy应用程序中禁用最小化和最大化按钮