1. 程式人生 > 其它 >count(DISTINCT col A,col B) 與先 group by col A,col B 效果一致

count(DISTINCT col A,col B) 與先 group by col A,col B 效果一致

技術標籤:mysqli

SELECT
	count( 1 ) 
FROM
	tb_contagion_record a,
	( SELECT student_id, id FROM tb_contagion_record GROUP BY student_id, contagion_event_id ) b 
WHERE
	a.is_delete = 0 
	AND a.id = b.id 
	AND a.org_id = 224285397914628097 
GROUP BY
	prefx
SELECT
	prefx,
	count( DISTINCT student_id, contagion_event_id )
FROM tb_contagion_record WHERE is_delete = 0 AND org_id = 224285397914628097 GROUP BY prefx