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

如何基于三个条件执行Lookup查询(含最值范围条件)

多条件范围匹配Lookup实现方案

Excel/Google Sheets 公式实现

逻辑说明

需同时满足三个匹配条件:

  • 目标表与Lookup表的Product完全一致
  • 目标表的Width值≥Lookup表的Min Width
  • 目标表的Width值≤Lookup表的Max Width

公式示例

假设Lookup表位于Sheet2!A:D,目标表的Width Group从C2单元格开始计算:

  • 新版Excel(365/2021,支持动态数组):
=XLOOKUP(1,(Sheet2!A:A=A2)*(Sheet2!B:B<=B2)*(Sheet2!C:C>=B2),Sheet2!D:D)
  • 旧版Excel/Google Sheets兼容写法:
=INDEX(Sheet2!D:D,MATCH(1,(Sheet2!A:A=A2)*(Sheet2!B:B<=B2)*(Sheet2!C:C>=B2),0))

提示:旧版Excel输入后需按Ctrl+Shift+Enter触发数组计算,Google Sheets直接回车即可生效。

SQL 查询实现

如果数据存储在数据库中,可通过关联查询实现匹配:

JOIN 写法

假设Lookup表名为width_lookup,目标表名为target_data:

SELECT 
    t.Product,
    t.Width,
    l.Width_Group
FROM target_data t
INNER JOIN width_lookup l 
    ON t.Product = l.Product
    AND t.Width BETWEEN l.Min_Width AND l.Max_Width;

子查询写法

SELECT 
    Product,
    Width,
    (SELECT Width_Group 
     FROM width_lookup l
     WHERE l.Product = t.Product
       AND t.Width >= l.Min_Width
       AND t.Width <= l.Max_Width) AS Width_Group
FROM target_data t;

注意:需保证Lookup表中同一Product的宽度区间无重叠,否则会返回多条匹配结果,需根据业务规则调整筛选逻辑。

内容的提问来源于stack exchange,提问作者H.K.

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 14:25:07