[{
"data": [{"operator": "1"},{"type": "1"},{"1": {"values": "3"}}],
"action": "6",
"coupon": ["130"],
"discount": "10",
"change_cart": "1",
"discount_type": "0",
"change_price_after_use": "0",
"show_in_additional_items": "1"
},
{
"data": [{"operator": "1"},{"type": "2"},{"2": {"values": "77"}}],
"action": "6",
"coupon": ["130"],
"discount": "200",
"change_cart": "0",
"discount_type": "1",
"change_price_after_use": "1",
"show_in_additional_items": "1"
},
{
"data": [{"operator": "1"},{"type": "3"},{"3": {"values": "151262"}}],
"action": "6",
"coupon": ["130"],
"discount": "10",
"change_cart": "1",
"discount_type": "0",
"change_price_after_use": "0",
"show_in_additional_items": "0"
}
]
структура данных в этом поле
CREATE TABLE action( `id` int NOT NULL PRIMARY KEY AUTO_INCREMENT, `condition` JSON );
INSERT INTO action (`condition`)
VALUES ('[{"data": [{"operator": "1"}, {"type": "1"}, {"1": {"values": "3"}}], "action": "6", "coupon": ["130"], "discount": "10", "change_cart": "1", "discount_type": "0", "change_price_after_use": "0", "show_in_additional_items": "1"}, {"data": [{"operator": "1"}, {"type": "2"}, {"2": {"values": "77"}}], "action": "6", "coupon": ["130"], "discount": "200", "change_cart": "0", "discount_type": "1", "change_price_after_use": "1", "show_in_additional_items": "1"}, {"data": [{"operator": "1"}, {"type": "3"}, {"3": {"values": "151262"}}], "action": "6", "coupon": ["130"], "discount": "10", "change_cart": "1", "discount_type": "0", "change_price_after_use": "0", "show_in_additional_items": "0"}]'),
('[{"action": ""}]'),
('[{"data": [{"operator": "1"}, {"type": "2"}, {"2": {"values": "24"}}, {"operator": "1"}, {"type": "1"}, {"1": {"values": "14"}}, {"operator": "1"}, {"type": "4"}, {"4": {"values": "1800"}}, {"operator": "1"}, {"type": "4"}, {"4": {"values": "1605"}}], "action": "5", "item_id": "165649", "discount": "1641", "show_in_list": "1", "discount_type": "1", "show_in_complect": "1", "show_in_additional_items": "1"}, {"data": [{"operator": "1"}, {"type": "2"}, {"2": {"values": "24"}}, {"operator": "1"}, {"type": "1"}, {"1": {"values": "14"}}, {"operator": "1"}, {"type": "4"}, {"4": {"values": "1800"}}, {"operator": "1"}, {"type": "4"}, {"4": {"values": "1609"}}, {"operator": "2"}, {"type": "3"}, {"3": {"values": "188603"}}], "action": "5", "item_id": "161922", "discount": "1641", "show_in_list": "1", "discount_type": "1", "show_in_complect": "1", "show_in_additional_items": "1"}, {"data": [{"operator": "1"}, {"type": "2"}, {"2": {"values": "24"}}, {"operator": "1"}, {"type": "1"}, {"1": {"values": "14"}}, {"operator": "1"}, {"type": "4"}, {"4": {"values": "1800"}}, {"operator": "1"}, {"type": "4"}, {"4": {"values": "1612"}}], "action": "5", "item_id": "161923", "discount": "2031", "show_in_list": "1", "discount_type": "1", "show_in_complect": "1", "show_in_additional_items": "1"}, {"data": [{"operator": "1"}, {"type": "2"}, {"2": {"values": "24"}}, {"operator": "1"}, {"type": "1"}, {"1": {"values": "14"}}, {"operator": "1"}, {"type": "4"}, {"4": {"values": "1800"}}, {"operator": "1"}, {"type": "4"}, {"4": {"values": "1617"}}, {"operator": "2"}, {"type": "3"}, {"3": {"values": "175359"}}], "action": "5", "item_id": "161929", "discount": "2551", "show_in_list": "1", "discount_type": "1", "show_in_complect": "1", "show_in_additional_items": "1"}, {"data": [{"operator": "1"}, {"type": "2"}, {"2": {"values": "24"}}, {"operator": "1"}, {"type": "1"}, {"1": {"values": "14"}}, {"operator": "1"}, {"type": "4"}, {"4": {"values": "1800"}}, {"operator": "1"}, {"type": "4"}, {"4": {"values": "1621"}}], "action": "5", "item_id": "161931", "discount": "3201", "show_in_list": "1", "discount_type": "1", "show_in_complect": "1", "show_in_additional_items": "1"}, {"data": [{"operator": "1"}, {"type": "2"}, {"2": {"values": "24"}}, {"operator": "1"}, {"type": "1"}, {"1": {"values": "14"}}, {"operator": "1"}, {"type": "4"}, {"4": {"values": "1800"}}, {"operator": "1"}, {"type": "4"}, {"4": {"values": "1624"}}], "action": "5", "item_id": "161932", "discount": "3851", "show_in_list": "1", "discount_type": "1", "show_in_complect": "1", "show_in_additional_items": "1"}, {"data": [{"operator": "1"}, {"type": "2"}, {"2": {"values": "24"}}, {"operator": "1"}, {"type": "1"}, {"1": {"values": "14"}}, {"operator": "1"}, {"type": "4"}, {"4": {"values": "1800"}}, {"operator": "1"}, {"type": "4"}, {"4": {"values": "1626"}}], "action": "5", "item_id": "161933", "discount": "4441", "show_in_list": "1", "discount_type": "1", "show_in_complect": "1", "show_in_additional_items": "1"}]'),
('[{"data": [{"operator": "1"}, {"type": "1"}, {"1": {"values": "3"}}], "action": "6", "coupon": ["130"], "discount": "10", "change_cart": "1", "discount_type": "0", "change_price_after_use": "0", "show_in_additional_items": "1"}, {"data": [{"operator": "1"}, {"type": "2"}, {"2": {"values": "77"}}], "action": "6", "coupon": ["130"], "discount": "200", "change_cart": "0", "discount_type": "1", "change_price_after_use": "1", "show_in_additional_items": "1"}, {"data": [{"operator": "1"}, {"type": "3"}, {"3": {"values": "151262"}}], "action": "6", "coupon": ["130"], "discount": "10", "change_cart": "1", "discount_type": "0", "change_price_after_use": "0", "show_in_additional_items": "0"}]'),
('[{"action": ""}]');
SELECT * FROM action WHERE json_contains(`condition`->'$[*].action', json_array("6"));
SELECT * FROM `action` WHERE `condition` LIKE '%"action": "6"%';
SELECT * FROM `action` WHERE JSON_SEARCH(`condition`, 'one', '6') IS NOT NULL;запрос для выборки всех записей у которых в поле 'condition' есть "action": "6"
SELECT DISTINCT action.*
FROM action
CROSS JOIN JSON_TABLE(action.`condition`,
'$[*].action' COLUMNS (action INT PATH '$')) jsontable
WHERE jsontable.action = 6