对我来说,这似乎很棘手,但事实确实如此。我得到了两个名为xp_guru_properties
和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
的{{1}}和street_name
以匹配xp_resale
的{{1}}。有人知道吗?提前致谢。急需帮助。
答案 0 :(得分:1)
您似乎想要联接和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'
。