邮政编码的第一部分

发布于 2024-12-15 16:55:42 字数 988 浏览 2 评论 0原文

我希望用户按邮政编码搜索,他们可以输入完整的邮政编码(例如:UB100PE / UB10 0PE)或邮政编码的第一部分(UB10)

我将使用 getUKPostcodeFirstPart("UB100PE") 来获取邮政编码的第一部分邮政编码

参考: getUKPostcodeFirstPart() by LazyOne

我想显示邮政编码第一部分的记录列表,这是应该如何完成的?

我应该在表中添加 stripped_postcode 字段吗?

像这样的东西::

SELECT records.company, records.full_postcode, area.* FROM records
  LEFT JOIN area on area.stripped_postcode = records.stripped_postcode AND records.id= area.record_id
WHERE records.stripped_postcode = "UB10"

它与两个表链接,recordsarea

record table:

  • id (PK)

  • company

  • 邮政编码

  • stripped_postcode

地区表:

  • id (PK)
  • record_id (FK)
  • stripped_postcode
  • 字段1
  • 字段2

I want user to search by postcode, they could enter full postcode (eg: UB100PE / UB10 0PE) or first part of postcode (UB10)

I will use getUKPostcodeFirstPart("UB100PE") to get first part of postcode

Ref: getUKPostcodeFirstPart() by LazyOne

I want to display a list of record from first part of postcode, is this how it should be done?

Should I add stripped_postcode field in the table?

Something like::

SELECT records.company, records.full_postcode, area.* FROM records
  LEFT JOIN area on area.stripped_postcode = records.stripped_postcode AND records.id= area.record_id
WHERE records.stripped_postcode = "UB10"

It is linked with two tables, records and area

record table:

  • id (PK)

  • company

  • postcode

  • stripped_postcode

area table:

  • id (PK)
  • record_id (FK)
  • stripped_postcode
  • field1
  • field2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

英雄似剑 2024-12-22 16:55:42

我有点困惑:为了避免在 SQL 中使用 like 似乎需要做很多工作。

SELECT records.company, records.full_postcode, area.[insert your fields here]
FROM records
 LEFT JOIN area 
   ON area.stripped_postcode = records.stripped_postcode 
  AND records.id= area.record_id
WHERE records.postcode like strSearch+'%'

I'm a bit confused: seems like a lot of work for avoiding the use of a like in SQL.

SELECT records.company, records.full_postcode, area.[insert your fields here]
FROM records
 LEFT JOIN area 
   ON area.stripped_postcode = records.stripped_postcode 
  AND records.id= area.record_id
WHERE records.postcode like strSearch+'%'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文