我现在有这张桌子
ID | Seller_Name | Seller_Non_Working_Day
1 | Seller A | [1,7]
2 | Seller B | [1]
3 | Seller C | []
4 | Seller D | [1,7]我试图提取卖家谁不是工作在星期天只,又名与1在Seller_Non_Working_Day。此字段为JSON类型。
这是我的查询,我没有得到任何响应:(
select * from table_name
where Seller_Non_Working_Day IN ('[1]')能帮上忙吗?
发布于 2020-08-05 12:24:12
MySQL JSON_OVERLAPS函数比较两个doc_path,如果值不匹配,则返回0;如果值不匹配,则返回1。
JSON_OVERLAPS(doc_path1, doc_path2)对于您的查询,我已经创建了第二个数组,其中一个值为1,即表示周日。这将比较所有记录并返回0和1。周日工作的卖家的查询结果将返回1。为了消除返回1的非必需记录,我添加了一个WHERE子句。下面是查询:
SELECT * FROM table_name
WHERE JSON_OVERLAPS(Seller_Non_Working_Day , '[1]') != 1 ;还有另一个函数JSON_CONTAINS,它将列出所有包含特定值的记录,例如JSON数组中任何位置的1。JSON_CONTAINS的语法为
JSON_CONTAINS(target, candidate[, path])
target is a specific field. Here it would be Seller_Non_Working_Day
candidate is a specific value to find. Here it would be [1]
Path is any specific array location which is optional.可以使用下面的查询来获取所有在星期天工作的卖家。
SELECT * FROM table_name
WHERE JSON_CONTAINS(Seller_Non_Working_Day , '[1]');https://stackoverflow.com/questions/63257838
复制相似问题