- if 下级角色全部为“流失” ==>“”流失“
else if 下级角色状态除了“流失”,就剩“预流失” ==>"预流失"
else ==>“活跃””
SELECT parent_id, CASE WHEN SUM(CASE WHEN status = '流失' THEN 1 ELSE 0 END) = COUNT(*) THEN '流失' WHEN SUM(CASE WHEN status IN ('流失', '预流失') THEN 1 ELSE 0 END) = COUNT(*) THEN '预流失' ELSE '活跃' END as aggregate_status FROM roles GROUP BY parent_id;
奇怪的需求&巧妙的SQL
于 2023-09-21 23:16:35 首次发布