mysql - Mysql比较两个表并匹配一些列的值并提取数据
问题描述
这对我来说似乎很棘手,但就是这样。我有两个名为xp_guru_properties
and的表xp_pn_resale
。在xp_pn_resale
表格中,我得到了列block
,type
在表格中,xp_guru_properties
我得到了列property_name
和json
。我想匹配这两列并从中获取列中的特定json
数据xp_guru_properties
。以下是一些示例数据,以免您感到困惑
xp_guru_properties,这次我搜索了一个参考xp_pn_resale表的数据
表中的json
字段
{
"id": 8174,
"typeCode": "HDB",
"name": "111 Lengkong Tiga",
"newLaunch": false,
"description": "111 Lengkong Tiga",
"totalUnits": null,
"floors": 0,
"topMonth": null,
"topYear": 1988,
"tenure": "L99",
"coverImageId": 3196890,
"districtCode": "D14",
"postcode": "410111",
"streetname": "Lengkong Tiga",
"streetname2": null,
"streetnumber": "111",
"longitude": 103.9114385,
"latitude": 1.324030239,
}
postcode
每当我从表中获得匹配时xp_resale
,我只想从 json 中获取或提取。guru_properties
就像我想111 Lengkong Tega
从两个表中匹配然后我应该得到postcode: 410111
. 但这似乎很难,因为我需要连接block
and street_name
fromxp_resale
以匹配property_name
from guru_properties
。有人有什么想法吗?提前致谢。急需帮助。
解决方案
您似乎想要一个连接和一个 json 提取:
select json_extract(g.json, '$.postcode') postcode
from xp_pn_resale p
inner join xp_guru_properties g
on g.property_name = concat(p.block, ' ', p.street_name)
json_extract(g.json, '$.postcode')
也可以写成:g.json->'$.postcode'
。
推荐阅读
- openedge - 如何在进度 4GL 上将字符转换为十进制?
- wpf - WPF 绑定背景为 SolidColorBrush
- javascript - Dart 中的 Javascript“地图”等价物是什么?
- android - Google Fitness:在没有反馈的情况下处理 TransactionTooLargeException
- ruby-on-rails - 如何在具有活动记录关联的设备中注册用户?
- virtualbox - 如何修复“virtualbox DHCP 服务器尚未为虚拟设备分配 IP 地址”
- docker - 如何将运行 Flask 应用程序的 minikube(kubernetes) 节点连接到 mysql docker 容器中的公共数据库?
- android - 关于Android架构组件中各个组件职责的问题
- ios - 使用 Observable 绑定 BehaviorRelay - RxSwift
- java - OO Spring REST API 设计——一种形式的转换或继承