Best way to join on a range?

前端 未结 3 1739
情歌与酒
情歌与酒 2021-01-19 23:30

I think this may be a common problem that may not have an answer for every tool. Right now we are trying to use amazons Redshift. The only problem we have now is we are tryi

3条回答
  •  终归单人心
    2021-01-20 00:09

    Try using between, listing the table with the target value second:

    select *
    from table1 t1
    join table2 t2
      on t2.ip between t1.startip and t1.endip
    

    And make sure there's an index on table2.ip.

    It should perform pretty well.

提交回复
热议问题