邮政编码的第一部分
我希望用户按邮政编码搜索,他们可以输入完整的邮政编码(例如: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"
它与两个表链接,records
和 area
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有点困惑:为了避免在 SQL 中使用 like 似乎需要做很多工作。
I'm a bit confused: seems like a lot of work for avoiding the use of a like in SQL.