根据另一个表行比较MySQL表中的值
我正在使用 CakePHP 开发一个应用程序系统。每份申请均包含申请人的地址和邮政编码(仅限英国)。
客户希望能够将“邮政编码区域”分配给其团队的指定成员。 不幸的是,邮政编码区域的格式和长度各不相同 - 示例:TA
、TQ1
、S60
、BS22
、TA6 4EJ
用户希望能够指定整个区域,或者根据需要在每个用户的基础上指定更具体的区域。
我需要能够获取每个前缀
并将其与邮政编码进行比较
每个应用程序,并返回任何匹配项。
用户Ross
管理邮政编码以BQ
开头的应用程序。 BS
和 S60
用户 Dave
管理具有完整邮政编码的应用程序:BS22 4JL
和 TA6 7EJ
>
我认为最好的方法是有一个充满用户定义的邮政编码前缀的表:
id | prefix
1 | TQ
2 | TL
3 | S50
4 | S55
5 | TA6 4EJ
每个用户都被分配一个邮政编码区域来管理。
我在想,如果我可以将每个应用程序邮政编码与每个前缀进行比较,我就可以检索给定邮政编码区域中的所有应用程序,然后查找该应用程序所属的用户。
id | postcode
1 | tq33 abc
2 | TL5 8HA
3 | s50 11l
不幸的是,邮政编码数据不是任何标准/常规格式;所以这可能会变得棘手。 听起来我需要将前缀
加入到邮政编码上;但由于没有钥匙,我认为这是不可能的。
前缀
和邮政编码
之间没有直接关联。感觉我错过了一些基本的东西
有什么指示吗?
I am working on an application system in CakePHP. Each application contains the address and a (UK only) postcode of the applicant.
The client wants to be able to assign "postcode areas" to a given member of their team.
Unfortunately the postcode area varies in format and length - examples: TA
, TQ1
, S60
, BS22
, TA6 4EJ
The user wants to be able to specify entire areas, or more specific areas on a per user basis if required.
I need to be able to take each prefix
and compare it to the postcode
for each application, and return any matches.
User Ross
manages applications with postcode beginning with: BQ
. BS
and S60
User Dave
manages applications with full postcodes: BS22 4JL
and TA6 7EJ
I figured that the best way would be to have a table full of user-defined postcode prefixes:
id | prefix
1 | TQ
2 | TL
3 | S50
4 | S55
5 | TA6 4EJ
Each user is assigned a postcode area to manage.
I'm thinking if I can compare each application postcode to each prefix, I can retrieve all applications in a given postcode area, then look up the user that this belongs.
id | postcode
1 | tq33 abc
2 | TL5 8HA
3 | s50 11l
The postcode data isn't in any standard/regular format unfortunately; so this might get tricky.
It sounds like I need to JOIN
the prefix
on to the postcode; but as there's no key I don't think that's possible.
There's no direct association between prefix
and postcode
. Feel like I'm missing something fundamental
Any pointers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
try: