You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何扩展INNER JOIN查询以获取多行数据?

修改后的SQL查询方案

你的原始查询通过s.fid = 996限制了仅返回该fid对应的行,要额外获取997和998的行,只需调整fid的过滤条件即可,有两种常用写法:

写法一:使用IN子句(推荐,更简洁)

select * from id i
inner join sval s 
on i.id = s.id 
where i.clid = 88 and s.fid IN (996, 997, 998) and s.val = 'XLON'

写法二:使用OR逻辑

select * from id i
inner join sval s 
on i.id = s.id 
where i.clid = 88 and (s.fid = 996 or s.fid = 997 or s.fid = 998) and s.val = 'XLON'

说明

  • 两种写法效果一致,IN子句在处理多个值时可读性更强。
  • 保留s.val = 'XLON'是假设997、998对应的行也需要满足val为'XLON'的条件,如果不需要这个限制,直接移除该条件即可。

内容的提问来源于stack exchange,提问作者user19667022

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 19:40:33