我们创建一个触发器
CREATE TRIGGER `insert_category` AFTER INSERT ON `cleaner_service`
FOR EACH ROW UPDATE users
SET user_category = (select group_concat(concat(service_id) SEPARATOR '-') from cleaner_service where users.id=cleaner_service.user_id)
WHERE users.id=NEW.user_id
它存储价值如 8-7-9 这个我想将此值存储在json [" 1"," 2" ," 3"] 你能告诉我如何在 MYSQL
中做到这一点请帮忙
答案 0 :(得分:0)
尝试:
SET user_category = concat("[",(select group_concat(concat(service_id) SEPARATOR ','),"]") from cleaner_service where users.id=cleaner_service.user_id)