我们最近发布了一个新的应用版本。我想找到选择医生咨询的客户(在(4,7)中有dpo.action)在new_app_version中的order_id中使用相同的药物
SELECT o.order_id, CASE WHEN o.app_version = '4.6.20' OR o.app_version = '4.6.21' OR o.app_version = '4.6.22' THEN 'new_version' ELSE 'old_version' END,m.medicine_name
FROM public."order" AS o
LEFT JOIN public.doctor_program_order AS dpo
ON o.order_id = dpo.order_id
LEFT JOIN public.medicine_notes AS m
ON o.order_id = m.order_id
WHERE dpo.action IN (4,7)
AND date(dateadd(minutes,330,o.order_placed_at)) BETWEEN '2018-03-01' AND '2018-06-01'
GROUP BY 1,2,3
HAVING COUNT(m.medicine_name) >1 ;