在 db 中的值之间进行搜索的最佳方法 [英] Best way to search between values in a db

查看:69
本文介绍了在 db 中的值之间进行搜索的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个查询来列出一组数字,例如 1000000 到 2000000,然后我在该 while 循环中运行另一个查询以查看它是否与另一个数据库中的另一个表匹配.这部分运行良好,但有点慢.

I have a query to list a set of numbers, for example 1000000 through 2000000, I then run another query in that while loop to see if it matches another table in another database. This part runs fine, but a little slow.

然后我需要进行另一个查询,如果它返回 false,那么它会对另一个表进行另一次检查.不过,我遇到的问题是,此表中的检查并不像匹配那样简单.

I then need to have another query such that if it returns false, then it does another check on yet another table. The problem I'm having though, is that the check in this table is not as simple as a match.

最后一张表的表结构是这样的:

The table structure on last table is like this:

  • firstnum
  • 第二个

这旨在用于一系列数字.例如,第 1 行可能是:

This is intended for use in a range of numbers. So row 1 for example might be:

1000023, 1000046

这意味着它适用于这些值之间和包括这些值的所有数字.数据库中有数千个这样的条目,我试图找出确定我正在搜索的特定数字是否存在于某个表中的最佳方法,但由于它不是直接匹配,我不是确定如何实现这一点.表也​​是PostgreSQL,主要查询是MySQL.

This would mean it's for all numbers between and including those values. There are thousands of these entries in the DB, and I'm trying to figure out the best way to determine if that particular number I'm searching on exists in that table somewhere, but since it's not a direct match, I'm not sure how to accomplish this. The table is also PostgreSQL while the main queries are MySQL.

推荐答案

有点难以理解你想表达的意思,但恐怕解决方案非常简单:... WHERE firstnum<= X AND X <= secondnum,其中 X 是您要查找的数字.

It's a bit hard to understand what you're trying to say, but I'm afraid the solution is ridiculously simple: ... WHERE firstnum <= X AND X <= secondnum, where X is the number you are looking for.

这篇关于在 db 中的值之间进行搜索的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆