将领先的0 ne添加到ZipCode是长度小于5个邮政编码

发布于 2025-01-21 07:54:47 字数 593 浏览 0 评论 0原文

我有一个包含邮政编码的表格,但是对于有领先0或0的Zips,它们被排除在外 - 我有

ALTER cbsa_locations CHANGE zip zip CHAR(5);
UPDATE cbsa_locations SET zip=LPAD(zip, 5, '0');

可在沙箱中更改表的工作。但这在我们的数据可视化软件中不起作用。是否有一种方法可以在查询中更新ZIP,然后将该表在同一查询中的邮政编码上加入另一个表。

前任。 Brokerage_Coverage Table具有Brokerage_code,ZIP,CBSA_LOCATIONS表具有Zip City,State,County。我想加入Zip上的那些,以获取该县的经纪人_Coverage,但CBSA_LOCATIONS ZIP FIELD缺少领先的0。

select bc.brokerage_code,
          bc.zip,
          cbsa.county
          from brokerage_coverage bc
          join cbsa_locations cbsa on cbsa.zip = bc.zip

I have a table that includes zip codes but for zips where there is a leading 0 or 0's they are excluded - I have

ALTER cbsa_locations CHANGE zip zip CHAR(5);
UPDATE cbsa_locations SET zip=LPAD(zip, 5, '0');

which works in changing the table in sandbox. But it doesn't work in our data visualization software. Is there a way to update the zip in a query and then join that table to another one on the zip code in the same query.

Ex. brokerage_coverage table has brokerage_code, zip and the cbsa_locations table has zip city, state, county. I want to join those on zip to get the county for brokerage_coverage but cbsa_locations zip field is missing the leading 0's.

select bc.brokerage_code,
          bc.zip,
          cbsa.county
          from brokerage_coverage bc
          join cbsa_locations cbsa on cbsa.zip = bc.zip

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

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

发布评论

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

评论(1

眼中杀气 2025-01-28 07:54:47

您可以在连接条件下使用缺少0的列添加列:

select bc.brokerage_code,
       bc.zip,
       cbsa.county
from brokerage_coverage bc
   join cbsa_locations cbsa on cbsa.zip = lpad(bc.zip, 5, '0')

You can pad the column with the missing 0 in the join condition:

select bc.brokerage_code,
       bc.zip,
       cbsa.county
from brokerage_coverage bc
   join cbsa_locations cbsa on cbsa.zip = lpad(bc.zip, 5, '0')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文