有距离时如何领导 [英] How to lead when having distance
问题描述
hello there
need your help for following problem if m having a master table as
<pre>
Lead_ID Lead_Name(KM)
0 1-8
1 1-25
2 1-50
3 1-100
4 1-150
5 1-200
7 1-300
和另一张距离表,如
and another table for distance , as
SocId GdnID Distance(KM)
x Y 20
A B 30
C D 15
E F 4
现在我需要从第1桌获得领先ID
,如果我得到距离= 4,那么领导ID将为0,因为它在1-8之间,不需要在1-25,1-50中检查,1-100 ......所以
类似如果我得到距离= 20那么领导ID将是1,因为它在1-25之间,不需要在1-50中检查...所以在
类似如果我得到35然后领先ID将是2,因为它在1-50之间而且不需要在1-100中检查......所以在
我尝试了什么:
尝试使用临时表消除后 - 并检查数字天气值是低或高,但我需要很长时间才能使用循环
Now i need to get the lead id from 1st table
such as if i get the distance = 4 then lead id will be 0 as it is between 1-8 and no need to check in 1-25, 1-50, 1-100 ...so on
similar if i get the distance = 20 then lead id will be 1 as it is between 1-25 and no need to check in 1-50 ...so on
similar if i get 35 then lead id will be 2 as it is between 1-50 and no need to check in 1-100 ...so on
What I have tried:
tried with temp table eliminate after - and check with digit wheather value is low or high, but i takes a long time as i m using loop
推荐答案
当你使用愚蠢的代码时会发生这种情况。
你正在处理范围:
0:1,8
1:9,25
2:26,50
等
您可以将这些高和低值添加到查找表中,并比较之间。
That's what happens when you use silly codes.
You're dealing with "ranges":
0: 1,8
1: 9,25
2: 26,50
etc.
You add those "high and low" values to your lookup table, and compare "between".
不要将数据存储为字符串,除非它们确实是并且将始终被视为字符串。姓名,地址,电话号码 - 它们都是字符串。
1-8,1-25等不是,因为你想把它们当作数字来查找如果有东西在一个范围内。
所以将它们存储为两个单独的数字!
Don't store data as strings, unless they genuinely are and will always be treated as, strings. Name, Addresses, phone numbers - they are all strings.
"1-8", "1-25" and so forth aren't, because you want to treat them as numbers in order to find out if something is in a range.
So store them as two separate numbers!
LeadID LeadMin LeadMax
0 1 8
1 9 25
2 26 50
...
现在,你的问题变得微不足道了:
Now, your problem becomes trivial:
SELECT LeadID FROM MyTable WHERE value BETWEEN LeadMin AND LeadMax
这篇关于有距离时如何领导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!