Count number of unique values

后端 未结 4 1127
予麋鹿
予麋鹿 2020-11-29 07:53

If I have three columns:

orderNumber, name, email

and I would like to count how many unique emails are in the table how would I go about do

4条回答
  •  不知归路
    2020-11-29 08:29

    For best performance you should use:

    SELECT 
    sub.email, 
    count(1) as 'count_unique' 
    FROM 
    (SELECT email FROM orders GROUP by email) sub
    

提交回复
热议问题