我有一个存储在json中的列
列名:s2s\U有效载荷
价值观:
{
"checkoutdate":"2019-10-31",
"checkindate":"2019-10-30",
"numtravelers":"2",
"domain":"www.travel.com.mx",
"destination": {
"country":"MX",
"city":"Manzanillo"
},
"eventtype":"search",
"vertical":"hotels"
}
我希望查询数组中的精确值,而不是返回某个数据类型的所有值。我用json提取得到不同的计数。
SELECT
COUNT(JSON_EXTRACT(s2s_payload, '$.destination.code')) AS total,
JSON_EXTRACT(s2s_payload, '$.destination.code') AS destination
FROM
"db"."events_data_json5_temp"
WHERE
id = '111000'
AND s2s_payload IS NOT NULL
AND yr = '2019'
AND mon = '10'
AND dt >= '26'
AND JSON_EXTRACT(s2s_payload, '$.destination.code')
GROUP BY
JSON_EXTRACT(s2s_payload, '$.destination.code')
如果我想筛选“eventtype”:“search”的位置,我该怎么做?
我尝试使用cast(s2s\u payload as char)='{“eventtype”“:”“search”}',但没有成功。
1条答案
按热度按时间kx5bkwkv1#
你需要使用
json_extract
+aCAST
要获取要比较的实际值,请执行以下操作:或者,和
json_extract_scalar
(因此不需要CAST
):