Best way to join on a range?

前端 未结 3 1733
情歌与酒
情歌与酒 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:08

    Assuming the range is contained within TableA, and the ID is in TableB, the following query should work with SQL

    SELECT TableA.*, TableB.*
    FROM TableA JOIN TableB 
    ON TableA.StartIP <= TableB.ID AND TableB.ID <= TableA.EndIP
    

提交回复
热议问题