Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Bug] 多表联查的问题 #766

Open
yjfgh5t opened this issue Sep 21, 2024 · 1 comment
Open

[Bug] 多表联查的问题 #766

yjfgh5t opened this issue Sep 21, 2024 · 1 comment

Comments

@yjfgh5t
Copy link

yjfgh5t commented Sep 21, 2024

APIJSON Version/APIJSON 版本号

6.2.0

Database Type & Version/数据库类型及版本号

MySql 5.7

Environment/环境信息

- JDK/基础库: 17
- OS/系统: Windows 11

APIAuto Screenshots/APIAuto 请求与结果完整截屏

有A、B两张表,我想实现 select A.,B. from A left join A.id = B.id where A.state=1 and B.state=1 ,请问如何实现啊!

Current Behavior/问题描述

有A、B两张表,我想实现  
select A.*,B.* from A 
left join A on A.id = B.id 
where A.state=1 and B.state=1 ,
请问如何实现啊!

现在使用left join 在左表上加查询条件,条件一直在子表里面 
select A.*,C.* from A 
left join (select B.* from B where B.state=1) as C on  A.id = C.id 
where A.state=1
这样次查询条件,无法排除B表的条件

Expected Behavior/期望结果

期望使用jion < 表查询时能实现如下Sql
select A.*,B.* from A 
left join A on A.id = B.id 
where A.state=1 and B.state=1

Any additional comments?/其它补充说明?

No response

@TommyLemon
Copy link
Collaborator

TommyLemon commented Sep 22, 2024

结果不一样吗?提前过滤性能还更好。
如果非要把副表 B 的条件后置处理,也可以放大 JOIN ON 上
把 B 的条件条件放到 ON 上

"join":{
   "</B":{
     "state":1
   }
}

https://github.com/Tencent/APIJSON/blob/master/Document.md#32-%E5%8A%9F%E8%83%BD%E7%AC%A6
image

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants